026
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<graphics.h>
#include<windows.h>
#include<Windowsx.h>
#include<dos.h>
#include<errno.h>
#include<string>
#include <fstream>
#include <sstream>
#include<io.h>
#include <time.h>
#pragma comment(lib,"Winmm.lib")

#define WIDTH 1200
#define HEIGHT 600
#define GRAVITY 0.1
////////////////////////////定义images
IMAGE im_bk;  // 定义图像对象
IMAGE ground1;
IMAGE ground2;
IMAGE background1;
IMAGE background2;
IMAGE background3;
IMAGE pause1;
IMAGE jxyx1;
IMAGE jxyx2;
IMAGE fhcd1;
IMAGE fhcd2;
IMAGE sz1;
IMAGE sz2;
IMAGE tc1;
IMAGE tc2;
IMAGE spells_effect1;
IMAGE no1walk[18];
IMAGE fno1walk[18];
IMAGE no1stand[12];
IMAGE fno1stand[12];
IMAGE menubk[16];
IMAGE menubk1;
IMAGE menuxyx1;
IMAGE menuds1;
IMAGE menusz1;
IMAGE menudq1;
IMAGE menuxyx2;
IMAGE menuds2;
IMAGE menusz2;
IMAGE menudq2;
IMAGE music_on;
IMAGE music_off;
IMAGE return_button;
IMAGE focusmouse_button;
IMAGE im_skill[12];
IMAGE im_skill_1_info;
IMAGE im_skill_1_info_2;
IMAGE im_enemy1;
IMAGE im_enemy2;
IMAGE scope1;

IMAGE enemy1_p;
IMAGE enemyshooter1_p;
IMAGE enemystrong1_p;
IMAGE enemyboss1_p;

IMAGE im_shop;
IMAGE im_money;
IMAGE im_shop_graph;
IMAGE im_blood_medicine;
IMAGE im_buy_button;
IMAGE im_buy_button2;
IMAGE im_shop_tips;
IMAGE im_confirm_button;
IMAGE im_confirm_button2;
IMAGE im_skill_1_explain;
IMAGE im_unlock;
IMAGE im_unlock_2;
IMAGE im_unlock2;

IMAGE im_gameover;
IMAGE im_return_menu;
IMAGE im_return_menu2;
///////////////////////////////////////以上为定义images

////////////////////////////////////////// 定义全局变量
bool nearboss = false;          //是否在boss附近
int Gamelevel = 1;              //游戏关数
int HistoricalGamelevel = 0;    //历史最高关数
int bkmusic_condition = 0;      //bgm状态
int begin_music_condition = 0;  //音乐四种状态，0为要关闭，1为保持关闭，2为要打开，3为保持关闭,4为静音状态
int boss_music = 0;             //boss音乐
int money_amount = 0;           //金币数

////////////////////////////////
////////////////////////////////////////////以下为部分提前声明的类与函数
/////注释说明：“+”号后表示新增的变量与函数，其中函数在“【  】”中。（为了简洁某些变量合在一起说出来了，例如坐标是由“x“”y“组成，若要查看详细信息可以转到类的定义内部查看）
class object;               ///////////物体类：+坐标
class moveobject;          ///////////移动物体类（继承物体类）：+血量 位置 速度 等级 【 重力 移动 】
class key;             ////////////钥匙类（继承物体类）：+存在 【 显示 获取钥匙 存档 读档】
class Bullet;               ///////////子弹类（继承物体类）：+等级 射出位置 速度 存在时间 存在 【 移动 现实 hit玩家 分裂 存档 读档 】
class player;               ////////////玩家类（继承移动物体类）：+血量恢复 魔法 飞行 经验 状态栏坐标 攻击  有钥匙 能移动 子弹[2002] 【射击 显示 控制 移动 复位 重置 显示状态栏 状态 存档 读档 】
class enemy;                ////////////enemy类：+存活 近战伤害 经验 体积【近战 被攻击 死亡 显示 浮台行走 复位 重置 显示状态栏 存档 读档 】
class enemyshooter;         ////////////enemyshooter类（继承enemy类）：+射击时间 射击伤害【 射击 】
class enemystrong;          /////////////enemystrong类（继承enemyshooter类）：+【 射击（变化较大） 】
class enemyboss;            /////////////enemyboss类：+【射击（变化较大） 死亡（变化较大） 】
class ground;               /////////////地面与浮台类（继承物体类）：+长度 厚度 【显示 物理性质 复位 存档 读档】
class graphfollow;          /////////////画面跟踪类：+ 画面坐标 目标坐标 画面移动 【 跟随  存档 读档 】
class Boundary;             /////////////边界类：+边界范围 【停止 显示背景】
class Mouse;                /////////////鼠标类（继承物体类）：鼠标修正数据 【 修正鼠标 显示 获取鼠标 】
class door;                 ////////////// 传送门类（继承物体类）：【显示 成功通过 复位 存档 读档 】
class SKILL_1;              //////////////
class SHOP;                 //////////////
class BufferTime;           //////////////
class LOADING;              //////////////
////////////////////////////////////////////////////////////////////
void putimagepng(int img_x, int img_y, IMAGE* pSrcImg);/////////////////经过修改，已适用于画面跟踪
void storedata();           //////////////总的存档函数
void readdata();            //////////////总的读档函数
void startup();             //////////////游戏开始
void show();                //////////////总的显示函数（为了运行速度，其中也有处理信息的函数）
void dowithinput();         //////////////处理主动输入信息函数
void dowithoutinput();      //////////////处理游戏信息函数
void time_loading();
//////////////////////////////////////////////////////命名空间
namespace all {
    void gameover();        //////////////游戏结束
    void restart();         //////////////新的游戏
    void drawAlpha(IMAGE* picture, int  picture_x, int picture_y); //x为要载入图片的X坐标，y为Y坐标（未使用）
    void pause();           //////////////暂停页面
    void menu();            //////////////主菜单
    void play_mainmenu_music();    //菜单音乐
    void play_bkmusic();    ///////////////播放背景音乐
    void settings();        ////////////////设置
    void nextlevel();       ///////////////下一关
    void battle();          ///////////////游戏战斗
    void move();            ///////////////移动
    void gravity();         ///////////////重力
    void staticobject();    ///////////////静止的物体（浮台与地面）对人的作用
    void allaboutenemy(player& name); ///////// 总的关于enemy的函数
    void allaboutbullet();  ///////////////总的关于野怪的函数
    void loading();         ///////////////加载页面
    void operate_bkmusic();
    void operate_begin_music();
}

////////////////////////////////////////////以上为部分提前声明的类与函数
///////////////////////////////////////////物体类
class object {
public:
    object(double a = 0, double b = 0) :x(a), y(b) {}
    double x;//////////////x坐标
    double y;//////////////y坐标
};

////////////////////////////////////////////钥匙类
class key :public object {
public:
    ////////////////////////////////随机生成位置
    key(double a = 9500 - rand() % 1000, double b = -300 + rand() % 300, bool c = true) :object(a, b), exist(c) {}
    bool exist;//////////////////是否存在
    void getkey(player& name);/////////////////////人物得到钥匙判定
    void show() {
        ///////////////////如果存在，则显示
        if (exist) {
            fillcircle(x, y, 10);
        }
    }
    virtual void storedata(FILE* fp);///////存档
    virtual void readdata(FILE* fp);///////读档
};
key key1;//////////地图随机产生的钥匙
key key2(0, 0, false);/////////////////打死boss掉的钥匙

/////////////////////////////移动物体类
class moveobject : public object {
public:
    moveobject(double a = 0, double b = 0, double c = 0, double d = 0, double e = 0, double f = 1,double g = 10) :object(a, b) {
        vx = c;
        vy = d;
        blood = e;
        bloodmax = e;
        level = f;
        volum = g;
    }
    double vx;////////////////x速度
    double vy;////////////////y速度
    double blood;/////////////////血量
    double bloodmax;//////////////////最大血量
    double level;////////////////等级
    double volum;///////////volum
    ///////////////////重力函数
    void gravity() {
        vy += GRAVITY;
        vy = fmin(4, vy);/////////////////使下落速度不会太大，优化游戏体验
    }
    virtual void move();////////////////移动函数
};

int no1bnum = 0;///////////////用于确定玩家该射出的子弹
int bnum = 0;//////////////用于确定enemy该射出的子弹

///////////////////////子弹类
class Bullet :public object {
public:
    Bullet(int a = 1) :level(a) {}
    int level = 1;////////////等级
    double xbegin = 0;//////////////射出点x坐标
    double ybegin = 0;//////////////射出点y坐标
    double vx = 0;//////////////x速度
    double vy = 0;//////////////y速度
    double v = 10;//////////////合速度
    int existtime = 0;//////////////子弹存在时间，用于消除子弹
    bool exist = false;///////////////是否存在
    void move();//////////////移动函数
    void show();/////////////显示函数
    void hitplayer(player& name);/////////////////子弹hit玩家
    void split();//////////////////子弹分裂
    virtual void storedata(FILE* fp);///////////////////存档
    virtual void readdata(FILE* fp);///////////////////读档
}bullet[2002];

//////////////////////玩家类
class player :public moveobject {
public:
    player(double a = WIDTH / 2, double b = HEIGHT / 2, double c = 0, double d = 0, double e = 100, double f = 1,double g = 20) :moveobject(a, b, c, d, e, f,g) {}
    double bloodrecovery = 0.002;/////////////自动血量恢复
    double magic = 100;/////////////魔法
    double magicmax = 100;/////////////最大魔法值
    double flytime = 1000;/////////////飞行时间
    double flytimemax = 1000;//////////////最大飞行时间
    double flytimerecovery = 0.3;/////////////////飞行时间恢复
    double experience = 0;/////////////////经验
    double infox = 20;////////////////状态栏显示x坐标（相对于窗口，不是画布）
    double infoy = 20;/////////////////状态栏显示y坐标（相对于窗口，不是画布）
    double attack = 10;/////////////////攻击伤害
    double attackenergy = 900;///////////////////攻击能量
    bool canmove = true;//////////////////是否能移动（用于被野怪近战伤害后，人物被弹开，短时间移动失效，防止玩家手还在按键上，继续靠近enemy ，血量被卡没）
    bool havekey = false;//////////////////是否拥有钥匙
    Bullet bullet[2002];///////////////////子弹2002个
    void shot(const Mouse& name);///////////////////////射击函数
    void show();///////////////////显示函数
    void control();////////////////////控制函数
    ////////////////////////移动函数
    void move() {
        x += vx;
        y += vy;
        ////////////////////////由于控制函数是给玩家速度（更顺滑），而不是直接位移，所以必须要有减速的办法
        ////////////////////////如果玩家松开按键就减速，在空中空也会减速，会显得很奇怪
        ////////////////////////这里模拟的是玩家在地面或者浮台上时会减速，效果较流畅
        if (fabs(vy) <= 0.1) {
            vx *= 0.97;
        }
    }
    ////////////////////复位函数，用于下一关
    void reset() {
        x = WIDTH / 2;
        y = HEIGHT / 2;
        vx = 0;
        vy = 0;
        blood = bloodmax;
        magic = magicmax;
        flytime = flytimemax;
        havekey = false;
        attackenergy = 900;
    }
    /////////////////////新游戏函数，初始化人物，用于新游戏
    void newgame() {
        x = WIDTH / 2;
        y = HEIGHT / 2;
        vx = 0;
        vy = 0;
        bloodmax = 100;
        blood = bloodmax;
        magicmax = 100;
        magic = magicmax;
        flytimemax = 1000;
        flytime = flytimemax;
        havekey = false;
        attack = 10;
        attackenergy = 900;
    }
    void showinfo(const graphfollow& name);////////////////////////显示状态栏
    void condition();///////////////////////玩家状态
    virtual void storedata(FILE* fp);///////////////////////////存档
    virtual void readdata(FILE* fp);/////////////////////////////读档
}no1;

//////////////////////enemy类
class enemy :public moveobject {
public:
    enemy(double a = rand() % 20000 + 700, double b = rand() % 50 * 20 - 1000, double c = 0.5 * (rand() % 5 - 2), double d = 0.5 * (rand() % 5 - 2), double e = 100, double f = 10, double g = 15) :moveobject(a, b, c, d, e,f),  exe(g) {}
    void closefight(player& name);///////////////近战函数
    void beattacked(player& name);///////////////被攻击函数
    virtual void die(int species) {   ///////////死亡函数（1,2,3 对应除boss以外的3种级别的野怪）
        if (blood <= 0 && alive) {
            no1.experience += exe;
            alive = false;
            if (species == 1)
            {
                money_amount += 10;//野怪死亡加钱
            }
            else if (species == 2)
            {
                money_amount += 20;//野怪死亡加钱
            }
            else if (species == 3)
            {
                money_amount += 40;//野怪死亡加钱
            }
        }
    }
    ////////////////////显示函数
    virtual void show() {
        if (alive) {
            putimagepng(x - 2 * volum, y - 2 * volum, &enemy1_p);
        }
    }
    virtual void walkback(const ground& name);/////////////////行走函数（防止走下浮台）
    ///////////////////复位函数，用于下一关
    virtual void reset() {
        x = rand() % 20000 + 700;
        y = rand() % 50 * 20 - 800;
        vx = 0.5 * (rand() % 5 - 2);
        bloodmax *= 1.5;
        closefightdamage *= 1.5;
        blood = bloodmax;
        alive = true;
        volum = 10;
    }
    ///////////////////初始化函数，用于新的游戏
    virtual void newgame() {
        x = rand() % 20000 + 700;
        y = rand() % 50 * 20 - 800;
        vx = 0.5 * (rand() % 5 - 2);
        bloodmax = 100;
        closefightdamage = 10;
        blood = bloodmax;
        alive = true;
    }
    /////////////////////显示enemy状态栏
    virtual void showinfo() {
        setfillcolor(HSVtoRGB(1, 0, 0.5));
        fillrectangle(x - 2 * volum, y - 3 * volum, x + 2 * volum, y - 3 * volum + 10 * volum / 15);
        setfillcolor(HSVtoRGB(1, 1, 1));
        fillrectangle(x - 2 * volum + 2, y - 3 * volum + 1, x + (4 * volum - 4) * blood / bloodmax - 2 - 2 * volum, y - 3 * volum + 10 * volum / 15 - 1);
    }
    virtual void storedata(FILE* fp);/////////////存档
    virtual void readdata(FILE* fp);/////////////读档
    bool alive = true;/////////////是否存活
    double closefightdamage = 10;////////////////近战伤害
    double exe = 15;////////////////死亡后玩家获取的经验


}enemy1[200];
const int enemy1number = 200;/////////////////enemy数量

///////////////////////enemyshooter类
class enemyshooter :public enemy {
public:
    enemyshooter() {
        exe = 30;
    }
    virtual void shot(const player& name);////////////射击函数
    double shoottime = 0;////////////射击时间，用于控制射击频率
    double shootdamdge = 8;//////////////射击伤害
    ////////////////显示函数
    virtual void show() {
        if (alive) {
            putimagepng(x - 2 * volum, y - 2 * volum, &enemyshooter1_p);
        }
    }
    /////////////////复位函数，用于下一关
    virtual void reset() {
        x = rand() % 20000 + 700;
        y = rand() % 50 * 20 - 800;
        vx = 0.5 * (rand() % 5 - 2);
        bloodmax *= 1.5;
        closefightdamage *= 1.5;
        blood = bloodmax;
        shootdamdge *= 1.5;
        alive = true;
    }
    //////////////初始化函数
    virtual void newgame() {
        x = rand() % 20000 + 700;
        y = rand() % 50 * 20 - 800;
        vx = 0.5 * (rand() % 5 - 2);
        bloodmax = 100;;
        closefightdamage = 10;
        blood = bloodmax;
        shootdamdge = 8;
        alive = true;
    }
    virtual void storedata(FILE* fp);////////////////////存档
    virtual void readdata(FILE* fp);///////////////////读档
}enemyshooter1[100];
const int enemyshooter1number = 100;//////////////enemyshooter数量

//////////////////////enemystrong类
class enemystrong :public enemyshooter {
public:
    enemystrong() {
        x = rand() % 5000 + 6000;
        y = rand() % 50 * 20 - 800;
        bloodmax = 700;
        blood = bloodmax;
        exe = 100;
        closefightdamage = 20;
        volum = 20;
    }
    virtual void shot(const player& name);///////////////射击函数
    ////////////////////显示函数
    virtual void show() {
        if (alive) {
            putimagepng(x - 2 * volum, y - 2 * volum, &enemystrong1_p);
        }
    }
    ///////////////复位函数
    virtual void reset() {
        x = rand() % 5000 + 6000;
        y = rand() % 50 * 20 - 800;
        bloodmax *= 1.5;
        closefightdamage *= 1.5;
        blood = bloodmax;
        shootdamdge *= 1.5;
        alive = true;
    }
    //////////////初始化函数
    virtual void newgame() {
        x = rand() % 5000 + 6000;
        y = rand() % 50 * 20 - 800;
        bloodmax = 700;
        closefightdamage = 20;
        blood = bloodmax;
        shootdamdge = 8;
        alive = true;
    }
    virtual void storedata(FILE* fp);/////////////////存档
    virtual void readdata(FILE* fp);///////////////读档
}enemystrong1[30];
const int enemystrong1number = 30;///////////////enemystrong数量

//////////////////enemyboss类
class enemyboss :public enemystrong {
public:
    enemyboss() {
        x = rand() % 4000 + 6500;
        y = rand() % 1000 - 700;
        vx = 0;
        vy = 0;
        bloodmax = 2000;
        blood = bloodmax;
        exe = 400;
        closefightdamage = 30;
        volum = 100;
    }
    virtual void shot(const player& name);////////////////////射击函数
    virtual void move(const player& name);////////////////////移动函数
    /////////////////显示函数
    virtual void show() {
        if (alive) {
            putimagepng(x - 2 * volum, y - 2 * volum, &enemyboss1_p);
        }
    }
    ///////////////////死亡函数
    void die() {
        if (blood <= 0 && alive) {
            key2.exist = true;
            key2.x = x;
            key2.y = y;
            no1.experience += exe;
            alive = false;
            //boss独立开来算钱，不用传入参数判断类别
            money_amount += 100;
        }
    }
    //////////////////复位函数
    virtual void reset() {
        x = rand() % 2000 + 8000;
        y = 0;
        bloodmax *= 1.5;
        closefightdamage *= 1.5;
        blood = bloodmax;
        shootdamdge *= 1.5;
        alive = true;
    }
    //////////////////////初始化函数
    virtual void newgame() {
        x = rand() % 2000 + 8000;
        y = 0;
        bloodmax = 2000;
        closefightdamage = 30;
        blood = bloodmax;
        shootdamdge = 10;
        alive = true;
    }
    virtual void storedata(FILE* fp);/////////////////////存档
    virtual void readdata(FILE* fp);////////////////////读档
}enemyboss1[15];
int enemyboss1number = 15;//////////////enemyboss数量

//////////////////////ground类
class ground :public object {
public:
    ground(double a = rand() % 12000 + 500, double b = rand() % 700 * 20 - 1200, double c = rand() % 400 + 150, double d = rand() % 20 + 10) :object(a, b), length(c), height(d) {}
    double length;///////////////////////长度
    double height;/////////////////////高度
    ////////////////////////显示函数
    void show() {
        setfillcolor(RGB(71, 86, 30));
        putimage(x, y, length, height, &ground2,0,0);
    }
    ////////////////////////ground的物理性质
    virtual void nature(moveobject& name) {
        if (x <= name.x && name.x <= x + length && y <= name.y+name.volum && name.y <= y + 4-name.volum) {
            name.y = y-name.volum;
            name.vy = 0;
        }
    }
    ////////////////////////复位
    void reset() {
        x = rand() % 12000 + 500;
        y = rand() % 70 * 20 - 1200;
        length = rand() % 400 + 150;
        height = rand() % 20 + 10;
    }
    virtual void storedata(FILE* fp);//////////////////////存档
    virtual void readdata(FILE* fp);///////////////////////读档
};
ground bottom(-2000, 400, 15000, 300);///////////////////地面
ground floatearth[200];
int floatearthnumber = 200;/////////////////浮台数量

class floatground :public  ground {
public:
    floatground(double a = 0, double b = 0, double c = 0, double d = 0) :ground(a, b, c, d) {}
    void nature(moveobject& name) {
        if (x <= name.x && name.x <= x + length && y <= name.y && name.y <= y + 10) {
            name.y = y;
            name.vy = 0;
        }
    }
};

//////////////////////////画面跟踪类
class graphfollow {
public:
    graphfollow(double a = 0, double b = 0, double c = WIDTH / 2, double d = HEIGHT / 2 + 70) :x(a), y(b), targetx(c), targety(d) {}
    double x;//////////画面x坐标
    double y;//////////画面y坐标
    double targetx;//////////目标x坐标
    double targety;///////////目标y坐标
    double movex = 0;///////////移动x距离
    double movey = 0;////////////移动y距离
    //////////////////画面跟随函数
    //////////////////原理是假设人物在画布上向一个方向移动一段距离，然后把画布反方向移动相同一段距离，这样人物就可以一直在窗口的中心了
    /////////////////画面跟随的速度与人物距离画面中心的距离有关，从额实现效果更佳顺滑
    void follow(const player& name) {
        movex = (name.x - targetx) * 0.04;/////////移动的x距离
        movey = (name.y - targety) * 0.04;/////////移动的y距离
        targetx += movex;///////////目标x近一点
        targety += movey;///////////目标y近一点
        x -= movex;///////////画布x调整
        y -= movey;///////////画布y调整
        setorigin(x, y);
    }
    virtual void storedata(FILE* fp);//////////////存档
    virtual void readdata(FILE* fp);///////////////读档
}graph;

////////////////////边界类
class Boundary {
public:
    double x1 = -2000;/////////////////左边界
    double x2 = 13000;//////////////////右边界
    double y1 = 450;/////////////////下边界
    double y2 = -1500;////////////////上边界
    ///////////////////边界性质的函数
    void stop(player& name) {
        if (name.x < -2000 + 10) {
            name.x = -1999 + 10;
            name.vx = 0;
        }
        if (name.x > 13000 - 10) {
            name.x = 13000 - 10;
            name.vx = 0;
        }
        if (name.y <= -1500 + 10) {
            name.y = -1499 + 10;
            name.vy = 0;
        }
    }
    ///////////////////背景显示函数，背景会随着人物移动而移动
    void showbackground(const graphfollow& name) {
        ////////////////////如果距离boss近，换背景
        if (nearboss) {
            putimage(-700 + name.targetx, -500 + name.targety, &background2);
        }
        else {
            putimage(-1000 + 0.9 * name.targetx, -800 + 0.9 * name.targety, &background3);
        }
        //putimage(-2000, 400, &ground2);
    }
};
Boundary boundary1;

////////////////////鼠标类
class Mouse :public object {
public:
    Mouse(double a = 0, double b = 0) :object(a, b) {}
    double fixx = 0;////////////////x方向修正
    double fixy = 0;////////////////y方向修正
    void fixmouse(const graphfollow& name);/////////////////////鼠标修正页面
    ///////////////////显示函数
    void show() {
        putimage(x - 24, y - 25, &scope1, MERGEPAINT);
    }
    //////////////////获取鼠标修正后位置
    void getmouse(const graphfollow& name) {
        SetConsoleTitleA("Get Cursor Postition");
        POINT pt;//////////////////鼠标原始位置
        BOOL bReturn = GetCursorPos(&pt); //获取鼠标指针位置到pt
        x = pt.x - name.x + fixx;////////////////修正后x位置
        y = pt.y - name.y + fixy;////////////////修正后y位置
    }
}mouse;

///////////////////传送门类
class door :public object {
public:
    door(double a = rand() % 3000 + 7000, double b = rand() % 400 - 500) :object(a, b) {}
    void show() {
        fillrectangle(x, y, x + 40, y - 200);
    }
    void succeed(const player& name);/////////////是否能通过门
    void reset() {
        x = rand() % 3000 + 7000;
        y = rand() % 400 - 500;
    }
    virtual void storedata(FILE* fp);/////////////存档
    virtual void readdata(FILE* fp);///////////////读档
}door1;

///////////////////////////透明通道函数
void putimagepng(int x, int y, IMAGE* pSrcImg)
{
    int img_x = x + graph.x;////////////////////此处x修正，以适应画面跟随
    int img_y = y + graph.y;/////////////////////此处y修正，以适应画面跟随
    DWORD* dst = GetImageBuffer();
    DWORD* src = GetImageBuffer(pSrcImg);
    int src_width = pSrcImg->getwidth();
    int src_height = pSrcImg->getheight();
    int dst_width = getwidth();
    int dst_height = getheight();

    int im_width, im_height;
    if (img_x + src_width > dst_width)
        im_width = dst_width - img_x;
    else
        im_width = src_width;
    if (img_y + src_height > dst_height)
        im_height = dst_height - img_y;
    else
        im_height = src_height;

    if (img_x < 0)
    {
        src = src - img_x;
        im_width = im_width + img_x;
        img_x = 0;
    }
    if (img_y < 0)
    {
        src = src - src_width * img_y;
        im_height = im_height + img_y;
        img_y = 0;
    }
    dst = dst + dst_width * img_y + img_x;

    for (int i = 0; i < im_height; i++)
    {
        for (int j = 0; j < im_width; j++)
        {
            int src_r = ((src[j] & 0xff0000) >> 16);
            int src_g = ((src[j] & 0xff00) >> 8);
            int src_b = src[j] & 0xff;
            int src_a = ((src[j] & 0xff000000) >> 24);
            int dst_r = ((dst[j] & 0xff0000) >> 16);
            int dst_g = ((dst[j] & 0xff00) >> 8);
            int dst_b = dst[j] & 0xff;
            dst[j] = ((src_r + dst_r * (255 - src_a) / 255) << 16)
                | ((src_g + dst_g * (255 - src_a) / 255) << 8)
                | (src_b + dst_b * (255 - src_a) / 255);
        }
        dst = dst + dst_width;
        src = src + src_width;
    }
}

///////////////////////////LOADING类
class LOADING
{
public:
    int N = 12; //N为小球个数
    int number = 1;  //小球序号
    int count = 1;   //计时
    int countmax = 50;
    double pi = 3.1415926;
    double radius_total = 200;
    double radius_basis = 26;
    float difference = 2;//两个相邻圆半径差值
    void draw(double x, double y)
    {
        int i;
        int n;
        setfillcolor(WHITE);
        for (i = 1; i <= N; i++)
        {
            double circlex = x + radius_total * cos(i * pi / N * 2);
            double circley = y + radius_total * sin(i * pi / N * 2);
            n = number - i;
            if (n > 0)
                solidcircle((int)circlex, (int)circley, radius_basis - (n * difference));
            if (n < 0)
                solidcircle((int)circlex, (int)circley, radius_basis - ((n + 12) * difference));
        }
        count++;
        if (count > countmax)
            count = 1;
        else if (count == countmax)
            number++;
        if (number > 12)
            number = 1;
    }
}loading1, loading3;

class SKILL_1     //火龙卷
{
public:
    int islock = 0;  //技能1是否解锁
    double n = 0.1;
    clock_t start, now; // 用于计时技能释放的变量
    clock_t startCD, nowCD;//用于计时技能CD
    double duration;  //技能释放的时间
    MOUSEMSG m;        // 定义鼠标消息
    int count = 0;
    int wait = 0;  //等CD，0为CD好的状态，1为等待状态
    float button_x = 1150, button_y = 275;  //图标位置
    double CD = 10;//技能冷却时长
    double countTime;  //剩余时长
    float x, y;    //技能释放坐标


    void draw()
    {
        if (islock == 1)
        {
            count++;
            if (count > 200)   //防连续按下
            {
                if (::GetAsyncKeyState('E') & 0x8000 && wait == 0) {
                    start = clock();//记录当前时刻,计时技能释放时间
                    startCD = clock();//记录CD开始计时
                    x = mouse.x - im_skill[1].getwidth() / 2; //更新坐标
                    y = mouse.y - im_skill[1].getheight();
                    no1.magic -= 30;
                    count = 0;
                    wait = 1;//给予等待CD信号
                }
            }
            if (count > 1000)
            {
                count = 201;
            }

            duration = (double(now - start) / CLOCKS_PER_SEC);
            now = clock();  //获得当前时刻



            if (duration < n)
                putimage(x, y, &im_skill[1], MERGEPAINT);
            else if (duration < 2 * n)
                putimage(x, y, &im_skill[2], MERGEPAINT);
            else if (duration < 3 * n)
                putimage(x, y, &im_skill[3], MERGEPAINT);
            else if (duration < 4 * n)
                putimage(x, y, &im_skill[4], MERGEPAINT);
            else if (duration < 5 * n)
                putimage(x, y, &im_skill[5], MERGEPAINT);
            else if (duration < 6 * n)
                putimage(x, y, &im_skill[6], MERGEPAINT);
            else if (duration < 7 * n)
                putimage(x, y, &im_skill[7], MERGEPAINT);
            else if (duration < 8 * n)
                putimage(x, y, &im_skill[8], MERGEPAINT);
            else if (duration < 9 * n)
                putimage(x, y, &im_skill[9], MERGEPAINT);
            else if (duration < 10 * n)
                putimage(x, y, &im_skill[10], MERGEPAINT);
            else if (duration < 11 * n)
                putimage(x, y, &im_skill[11], MERGEPAINT);



            draw_button();
        }

    }

    void draw_button()
    {
        setbkmode(TRANSPARENT); // 透明显示文字
        settextcolor(BLACK);  // 设置字体颜色
        settextstyle(40, 0, _T("宋体")); // 设置文字大小、字体
        TCHAR str[20]; // 定义字符数组
        nowCD = clock();
        if ((double(nowCD - startCD) / CLOCKS_PER_SEC) >= CD)
        {
            putimage(-graph.x + button_x - 20, -graph.y + button_y, &im_skill_1_info);
            wait = 0;
        }
        else
        {
            putimage(-graph.x + button_x - 20, -graph.y + button_y, &im_skill_1_info_2);

            countTime = CD + 1 - double(nowCD - startCD) / CLOCKS_PER_SEC;//计算剩余时长
            swprintf_s(str, 20, _T("%ds"), int(countTime)); //转换为字符串
            outtextxy(-graph.x + button_x - 20, -graph.y + button_y, str); // 输出文字
        }

    }
    void skill_hitenemy(double* ex, double* ey, double* blood)   //判定技能攻击敌人
    {
        if (duration < 11 * n && duration > 0)  //技能释放过程中
        {
            if (fabs(*ex - x) <= im_skill[1].getwidth() / 2 && fabs(*ey - y) <= im_skill[1].getheight())
            {
                *blood -= no1.level * 1; //持续伤害，每进入一次循环血量-1
            }
        }
    }
    void storedata(FILE* fp);
    void readdata(FILE* fp);
}skill_1;

//////////////////////商店类
class SHOP
{
public:
    float button_x = 25, button_y = 275;
    float window_x = 50, window_y = 50;
    void drawbutton()
    {
        putimage(-graph.x + button_x - 20, -graph.y + button_y, &im_shop);
        putimagepng(-graph.x + button_x - 20, -graph.y + button_y + 50, &im_money);

        setbkmode(TRANSPARENT); // 透明显示文字
        settextcolor(WHITE);  // 设置字体颜色
        settextstyle(20, 0, _T("宋体")); // 设置文字大小、字体
        TCHAR str[20]; // 定义字符数组
        swprintf_s(str, 20, _T("%d"), money_amount); //转换为字符串
        outtextxy(-graph.x + button_x, -graph.y + button_y + 50, str);
    }
    void open_graph()
    {
        while (1)
        {
            BeginBatchDraw();
            cleardevice();
            mouse.getmouse(graph);
            putimagepng(-graph.x + window_x, -graph.y + window_y, &im_shop_graph);//商店面板

            setbkmode(TRANSPARENT); // 透明显示文字
            settextcolor(BLACK);  // 设置字体颜色
            settextstyle(40, 0, _T("华文琥珀")); // 设置文字大小、字体
            TCHAR str[20]; // 定义字符数组
            static int merchandise_num = 0;

            //商品1：血药
            putimage(-graph.x + window_x + 55, -graph.y + window_y + 130, &im_blood_medicine);
            if (-graph.x + window_x + 55 <= mouse.x && mouse.x <= -graph.x + window_x + 55 + 50 && -graph.y + window_y + 130 <= mouse.y && mouse.y <= -graph.y + window_y + 130 + 50) {
                if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                    merchandise_num = 1;  //商品编号为1
                }
            }


            //商品2：技能1
            putimage(-graph.x + window_x + 55 + 390, -graph.y + window_y + 130, &im_skill_1_info);
            if (-graph.x + window_x + 55 + 390 <= mouse.x && mouse.x <= -graph.x + window_x + 55 + 390 + 50 && -graph.y + window_y + 130 <= mouse.y && mouse.y <= -graph.y + window_y + 130 + 50) {
                if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                    merchandise_num = 2;  //商品编号为1
                }
            }

            merchandise_explain(merchandise_num);

            putimagepng(-graph.x + 900, -graph.y + 200, &return_button);//返回按钮
            putimage(-graph.x + 900, -graph.y + 300, &im_shop);
            putimagepng(-graph.x + 900, -graph.y + 300 + 50, &im_money);  //钱币数

            settextcolor(WHITE);  // 设置字体颜色
            settextstyle(20, 0, _T("宋体")); // 设置文字大小、字体
            swprintf_s(str, 20, _T("%d"), money_amount); //转换为字符串
            outtextxy(-graph.x + 900 + 25, -graph.y + 300 + 50, str);



            FlushBatchDraw();
            if (900 - graph.x <= mouse.x && mouse.x <= 1100 - graph.x && 200 - graph.y <= mouse.y && mouse.y <= 275 - graph.y) {
                if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                    break;
                }
            }
        }
    }

    void merchandise_explain(int merchandise_num)
    {
        static int cnt = 0;   //防连触
        static int ispoor = 0; //判断是否余额不足
        if (cnt < 200)
            cnt++;

        setbkmode(TRANSPARENT); // 透明显示文字
        settextcolor(BLACK);  // 设置字体颜色

        TCHAR str[20]; // 定义字符数组

        if (merchandise_num == 1)   //血药
        {
            swprintf_s(str, 20, _T("回复血量50点")); //商品1的文字介绍
            outtextxy(-graph.x + window_x + 150, -graph.y + window_y + 200, str);
            swprintf_s(str, 20, _T("50金币")); //商品1的价格
            outtextxy(-graph.x + window_x + 150, -graph.y + window_y + 250, str);
            if (-graph.x + window_x + 150 <= mouse.x && mouse.x <= -graph.x + window_x + 150 + 230 && -graph.y + window_y + 350 <= mouse.y && mouse.y <= -graph.y + window_y + 350 + 56)
            {
                putimagepng(-graph.x + window_x + 150 - 10, -graph.y + window_y + 350 - 3, &im_buy_button2);
                if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000 && cnt == 200) {
                    cnt = 0;
                    putimagepng(-graph.x + window_x + 150, -graph.y + window_y + 350, &im_buy_button);
                    if (money_amount >= 50)
                    {
                        money_amount -= 50;  //减钱
                        no1.blood += 50;  //加血量
                    }
                    else
                    {
                        ispoor = 1;  //判断出余额不足
                    }
                    if (no1.blood > no1.bloodmax)
                        no1.blood = no1.bloodmax;
                }
            }
            else
            {
                putimagepng(-graph.x + window_x + 150, -graph.y + window_y + 350, &im_buy_button);
            }

        }

        if (merchandise_num == 2)
        {
            putimagepng(-graph.x + window_x + 150 + 370, -graph.y + window_y + 150, &im_skill_1_explain);
            if (skill_1.islock == 0)//还未解锁
            {
                if (-graph.x + window_x + 550 <= mouse.x && mouse.x <= -graph.x + window_x + 550 + 200
                    && -graph.y + window_y + 300 <= mouse.y && mouse.y <= -graph.y + window_y + 300 + 100)
                {
                    putimagepng(-graph.x + window_x + 550 - 10, -graph.y + window_y + 300 - 5, &im_unlock_2);
                    if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000 && cnt == 200) {
                        cnt = 0;
                        if (money_amount >= 200)
                        {
                            money_amount -= 200;  //减钱
                            skill_1.islock = 1;   //解锁
                        }
                        else
                        {
                            ispoor = 1;  //判断出余额不足
                        }

                    }
                }
                else
                    putimagepng(-graph.x + window_x + 550, -graph.y + window_y + 300, &im_unlock);
            }
            else if (skill_1.islock == 1)
                putimagepng(-graph.x + window_x + 550, -graph.y + window_y + 300, &im_unlock2);
        }

        if (ispoor == 1)       //余额不足界面
        {
            putimagepng(-graph.x + 400, -graph.y + 220, &im_shop_tips);
            if (-graph.x + 400 + im_shop_tips.getwidth() / 2 - im_confirm_button.getwidth() / 2 <= mouse.x && mouse.x <= -graph.x + 400 + im_shop_tips.getwidth() / 2 - im_confirm_button.getwidth() / 2 + 80
                && -graph.y + 220 + 40 + im_shop_tips.getheight() / 2 - im_confirm_button.getheight() / 2 <= mouse.y && mouse.y <= -graph.y + 220 + 40 + im_shop_tips.getheight() / 2 - im_confirm_button.getheight() / 2 + 40)
            {
                putimagepng(-graph.x + 400 + im_shop_tips.getwidth() / 2 - im_confirm_button.getwidth() / 2 - 4, -graph.y + 220 + 40 + im_shop_tips.getheight() / 2 - im_confirm_button.getheight() / 2 - 2, &im_confirm_button2);
                if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000)
                {
                    ispoor = 0;
                }
            }
            else
            {
                putimagepng(-graph.x + 400 + im_shop_tips.getwidth() / 2 - im_confirm_button.getwidth() / 2, -graph.y + 220 + 40 + im_shop_tips.getheight() / 2 - im_confirm_button.getheight() / 2, &im_confirm_button);
            }


            settextcolor(WHITE);  // 设置字体颜色
            settextstyle(20, 0, _T("华文琥珀")); // 设置文字大小、字体
            swprintf_s(str, 20, _T("您的余额不足"));
            outtextxy(-graph.x + 400 + im_shop_tips.getwidth() / 2 - 60, -graph.y + 220 + im_shop_tips.getheight() / 2 - 20, str);
        }

    }
}shop;

/////////////////////////Buffertime类
class BufferTime {
public:

}BufferTime1;
/////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////main主函数
int main() {
    /////////////////加载images和音乐（放主函数里运行相对流畅）

    loadimage(&scope1, _T("scope01.JPG"), 50, 50);
    loadimage(&enemy1_p, _T("enemy1.png"), 4 * enemy1[0].volum, 4 * enemy1[0].volum);
    loadimage(&enemyshooter1_p, _T("enemy2.png"), 4 * enemyshooter1[0].volum, 4 * enemyshooter1[0].volum);
    loadimage(&enemystrong1_p, _T("enemy3.png"), 4 * enemystrong1[0].volum, 4 * enemystrong1[0].volum);
    loadimage(&enemyboss1_p, _T("enemy4.png"), 4 * enemyboss1[0].volum, 4 * enemyboss1[0].volum);

    loadimage(&scope1, _T("scope06.JPG"), 50, 50);
    loadimage(&im_bk, _T("图片 1.png")); // 导入背景图片
    loadimage(&ground1, _T("ground001.jpg"), 800, 20, TRUE);
    loadimage(&ground2, _T("ground002.jpg"), 15000, 200, TRUE);
    loadimage(&background1, _T("background001.jpg"), 2000, 1000, TRUE);
    loadimage(&background2, _T("background002.jpg"), 1600, 1000, TRUE);
    loadimage(&background3, _T("background003.jpg"), 4800, 1500, TRUE);
    loadimage(&pause1, _T("pause001.jpg"), 1200, 600, TRUE);
    loadimage(&jxyx1, _T("jxyx002.JPG"), 400, 100, TRUE);
    loadimage(&jxyx2, _T("jxyx002.JPG"), 440, 110, TRUE);
    loadimage(&fhcd1, _T("fhcd001.JPG"), 400, 100, TRUE);
    loadimage(&fhcd2, _T("fhcd001.JPG"), 440, 110, TRUE);
    loadimage(&sz1, _T("sz001.JPG"), 400, 100, TRUE);
    loadimage(&sz2, _T("sz001.JPG"), 440, 110, TRUE);
    loadimage(&tc1, _T("tc001.JPG"), 400, 100, TRUE);
    loadimage(&tc2, _T("tc001.JPG"), 440, 110, TRUE);
    //loadimage(&spells_effect1, _T("spells_effect001.png"), 20, 20, TRUE);

    loadimage(&no1walk[0], _T("no1walk001.png"), 100, 80, TRUE);
    loadimage(&no1walk[1], _T("no1walk002.png"), 100, 80, TRUE);
    loadimage(&no1walk[2], _T("no1walk003.png"), 100, 80, TRUE);
    loadimage(&no1walk[3], _T("no1walk004.png"), 100, 80, TRUE);
    loadimage(&no1walk[4], _T("no1walk005.png"), 100, 80, TRUE);
    loadimage(&no1walk[5], _T("no1walk006.png"), 100, 80, TRUE);
    loadimage(&no1walk[6], _T("no1walk007.png"), 100, 80, TRUE);
    loadimage(&no1walk[7], _T("no1walk008.png"), 100, 80, TRUE);
    loadimage(&no1walk[8], _T("no1walk009.png"), 100, 80, TRUE);
    loadimage(&no1walk[9], _T("no1walk010.png"), 100, 80, TRUE);
    loadimage(&no1walk[10], _T("no1walk011.png"), 100, 80, TRUE);
    loadimage(&no1walk[11], _T("no1walk012.png"), 100, 80, TRUE);
    loadimage(&no1walk[12], _T("no1walk013.png"), 100, 80, TRUE);
    loadimage(&no1walk[13], _T("no1walk014.png"), 100, 80, TRUE);
    loadimage(&no1walk[14], _T("no1walk015.png"), 100, 80, TRUE);
    loadimage(&no1walk[15], _T("no1walk016.png"), 100, 80, TRUE);
    loadimage(&no1walk[16], _T("no1walk017.png"), 100, 80, TRUE);
    loadimage(&no1walk[17], _T("no1walk018.png"), 100, 80, TRUE);

    loadimage(&fno1walk[0], _T("fno1walk001.png"), 100, 80, TRUE);
    loadimage(&fno1walk[1], _T("fno1walk002.png"), 100, 80, TRUE);
    loadimage(&fno1walk[2], _T("fno1walk003.png"), 100, 80, TRUE);
    loadimage(&fno1walk[3], _T("fno1walk004.png"), 100, 80, TRUE);
    loadimage(&fno1walk[4], _T("fno1walk005.png"), 100, 80, TRUE);
    loadimage(&fno1walk[5], _T("fno1walk006.png"), 100, 80, TRUE);
    loadimage(&fno1walk[6], _T("fno1walk007.png"), 100, 80, TRUE);
    loadimage(&fno1walk[7], _T("fno1walk008.png"), 100, 80, TRUE);
    loadimage(&fno1walk[8], _T("fno1walk009.png"), 100, 80, TRUE);
    loadimage(&fno1walk[9], _T("fno1walk010.png"), 100, 80, TRUE);
    loadimage(&fno1walk[10], _T("fno1walk011.png"), 100, 80, TRUE);
    loadimage(&fno1walk[11], _T("fno1walk012.png"), 100, 80, TRUE);
    loadimage(&fno1walk[12], _T("fno1walk013.png"), 100, 80, TRUE);
    loadimage(&fno1walk[13], _T("fno1walk014.png"), 100, 80, TRUE);
    loadimage(&fno1walk[14], _T("fno1walk015.png"), 100, 80, TRUE);
    loadimage(&fno1walk[15], _T("fno1walk016.png"), 100, 80, TRUE);
    loadimage(&fno1walk[16], _T("fno1walk017.png"), 100, 80, TRUE);
    loadimage(&fno1walk[17], _T("fno1walk018.png"), 100, 80, TRUE);

    loadimage(&no1stand[0], _T("no1stand001.png"), 100, 80, TRUE);
    loadimage(&no1stand[1], _T("no1stand002.png"), 100, 80, TRUE);
    loadimage(&no1stand[2], _T("no1stand003.png"), 100, 80, TRUE);
    loadimage(&no1stand[3], _T("no1stand004.png"), 100, 80, TRUE);
    loadimage(&no1stand[4], _T("no1stand005.png"), 100, 80, TRUE);
    loadimage(&no1stand[5], _T("no1stand006.png"), 100, 80, TRUE);
    loadimage(&no1stand[6], _T("no1stand007.png"), 100, 80, TRUE);
    loadimage(&no1stand[7], _T("no1stand008.png"), 100, 80, TRUE);
    loadimage(&no1stand[8], _T("no1stand009.png"), 100, 80, TRUE);
    loadimage(&no1stand[9], _T("no1stand010.png"), 100, 80, TRUE);
    loadimage(&no1stand[10], _T("no1stand011.png"), 100, 80, TRUE);
    loadimage(&no1stand[11], _T("no1stand012.png"), 100, 80, TRUE);

    loadimage(&fno1stand[0], _T("fno1stand001.png"), 100, 80, TRUE);
    loadimage(&fno1stand[1], _T("fno1stand002.png"), 100, 80, TRUE);
    loadimage(&fno1stand[2], _T("fno1stand003.png"), 100, 80, TRUE);
    loadimage(&fno1stand[3], _T("fno1stand004.png"), 100, 80, TRUE);
    loadimage(&fno1stand[4], _T("fno1stand005.png"), 100, 80, TRUE);
    loadimage(&fno1stand[5], _T("fno1stand006.png"), 100, 80, TRUE);
    loadimage(&fno1stand[6], _T("fno1stand007.png"), 100, 80, TRUE);
    loadimage(&fno1stand[7], _T("fno1stand008.png"), 100, 80, TRUE);
    loadimage(&fno1stand[8], _T("fno1stand009.png"), 100, 80, TRUE);
    loadimage(&fno1stand[9], _T("fno1stand010.png"), 100, 80, TRUE);
    loadimage(&fno1stand[10], _T("fno1stand011.png"), 100, 80, TRUE);
    loadimage(&fno1stand[11], _T("fno1stand012.png"), 100, 80, TRUE);

    loadimage(&menuds1, _T("menuds.jpg"), 285, 50, TRUE);
    loadimage(&menuxyx1, _T("menuxyx.jpg"), 285, 50, TRUE);
    loadimage(&menusz1, _T("menusz.jpg"), 285, 50, TRUE);
    loadimage(&menudq1, _T("menudq.jpg"), 285, 50, TRUE);
    loadimage(&menuds2, _T("menuds.jpg"), 313, 55, TRUE);
    loadimage(&menuxyx2, _T("menuxyx.jpg"), 313, 55, TRUE);
    loadimage(&menusz2, _T("menusz.jpg"), 313, 55, TRUE);
    loadimage(&menudq2, _T("menudq.jpg"), 313, 55, TRUE);

    loadimage(&music_on, _T("music_on.png"), 75, 75, TRUE);
    loadimage(&music_off, _T("music_off.png"), 75, 75, TRUE);
    loadimage(&return_button, _T("return_button.png"), 200, 75, TRUE);   //设置中返回键按钮
    loadimage(&focusmouse_button, _T("focusmouse_button.png"), 75, 75, TRUE);  //校准按钮

    loadimage(&im_skill[1], _T("skill_1.png"));  //技能图片     287，353图片原大小
    loadimage(&im_skill[2], _T("skill_2.png"));  //技能图片
    loadimage(&im_skill[3], _T("skill_3.png"));  //技能图片
    loadimage(&im_skill[4], _T("skill_4.png"));  //技能图片
    loadimage(&im_skill[5], _T("skill_5.png"));  //技能图片
    loadimage(&im_skill[6], _T("skill_6.png"));  //技能图片
    loadimage(&im_skill[7], _T("skill_7.png"));  //技能图片
    loadimage(&im_skill[8], _T("skill_8.png"));  //技能图片
    loadimage(&im_skill[9], _T("skill_9.png"));  //技能图片
    loadimage(&im_skill[10], _T("skill_10.png"));  //技能图片
    loadimage(&im_skill[11], _T("skill_11.png"));  //技能图片
    loadimage(&im_skill_1_info, _T("skill_1_info.png"), 50, 50, TRUE); //技能图标
    loadimage(&im_skill_1_info_2, _T("skill_1_info_2.png"), 50, 50, TRUE); //技能图标

    loadimage(&im_enemy1, _T("enemy1.png"), 20, 20, true);//野怪图片
    loadimage(&im_enemy2, _T("enemy2.jpg"), 40, 40, true);//

    loadimage(&im_shop, _T("shop.jpg"), 50, 50, true);//商店图标
    loadimage(&im_money, _T("money.png"), 20, 20, true);//金币图标
    loadimage(&im_shop_graph, _T("shop_graph.png"));//商店界面
    loadimage(&im_blood_medicine, _T("blood_medicine.jpg"), 50, 50, true);//商品：血药
    loadimage(&im_buy_button, _T("buy_button.png"), 230, 56, true);  //确认购买并使用按钮
    loadimage(&im_buy_button2, _T("buy_button.png"), 250, 62, true);  //确认购买并使用按钮
    loadimage(&im_shop_tips, _T("shop_tips.png"));  //商店提示信息窗口
    loadimage(&im_confirm_button, _T("confirm_button.png"), 80, 40, true);  //确认按钮
    loadimage(&im_confirm_button2, _T("confirm_button.png"), 88, 44, true);
    loadimage(&im_skill_1_explain, _T("skill_1_explain.png"), 232, 104, true); //技能1介绍
    loadimage(&im_unlock, _T("unlock.png"), 200, 100, true);  //解锁
    loadimage(&im_unlock_2, _T("unlock.png"), 220, 110, true);
    loadimage(&im_unlock2, _T("unlock2.png"), 200, 100, true);

    loadimage(&im_gameover, _T("gameover.png"), 1200, 600, true);
    loadimage(&im_return_menu, _T("return_to_menu.png"), 450, 100, true);
    loadimage(&im_return_menu2, _T("return_to_menu.png"), 500, 120, true);

    mciSendString(_T("open beginmusic.mp3 alias begin_music"), NULL, 0, NULL);   //打开菜单音乐
    mciSendString(_T("open bkmusic1.mp3 alias bk_music"), NULL, 0, NULL);   //打开背景音乐



    ////////////////以上为加载images和音乐
    startup();////////////游戏开始

    return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////main

void startup() {
    //播放菜单音乐
    begin_music_condition = 2;
    all::operate_begin_music();
    FILE* fp;
    fopen_s(&fp, "Data.txt", "r");
    fscanf_s(fp, "%d", &HistoricalGamelevel);
    fclose(fp);
    initgraph(WIDTH, HEIGHT);
    all::loading();//加载页面
    mouse.fixmouse(graph);  //鼠标校准界面
    time_loading();  //加载界面
    all::menu();  //打开主菜单

}

void show() {
    BeginBatchDraw();
    cleardevice();
    boundary1.showbackground(graph);///////////////显示背景
    bottom.show();/////////////////地面显示
    /////////////////////////浮台显示
    for (int i = 0; i < floatearthnumber; i++) {
        floatearth[i].show();
    }
    door1.show();////////////////传送门
    key1.show();///////////////显示钥匙1
    key2.show();///////////////显示钥匙2
    no1.show();/////////////////显示玩家
    all::allaboutenemy(no1);/////////////////所有与enemy相关的函数
    all::allaboutbullet();///////////////////所有与子弹相关的函数
    no1.showinfo(graph);///////////////////显示玩家状态栏
    no1.shot(mouse);///////////////////玩家射击
    mouse.show();//////////////////显示鼠标

    //技能1
    skill_1.draw();

    //商店图标
    shop.drawbutton();

    FlushBatchDraw();
}

void dowithinput() {
    no1.control();///////////////玩家控制


    //暂停
    if (::GetAsyncKeyState('P') & 0x8000) {
        all::pause();
    }

    //商店
    if (-graph.x + shop.button_x - 20 <= mouse.x && mouse.x <= -graph.x + shop.button_x + 30
        && -graph.y + shop.button_y <= mouse.y && mouse.y <= -graph.y + shop.button_y + 50)
    {
        if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
            shop.open_graph();
        }
    }
}

void dowithoutinput() {
    all::gravity();//////////////重力
    all::move();///////////////移动
    all::staticobject();//////////////静止物体（地面与浮台）效果
    graph.follow(no1);//////////////画面跟随
    no1.condition();//////////////玩家状态
    mouse.getmouse(graph);//////////////获取鼠标位置
    key1.getkey(no1);/////////////判断玩家获取钥匙1
    key2.getkey(no1);/////////////判断玩家获取钥匙2
    door1.succeed(no1);////////////成功通过门，进入下一关
    boundary1.stop(no1);/////////////边界效果
}

void all::battle() {
    if (bkmusic_condition != 5 && bkmusic_condition != 3) //打开游戏音乐
    {
        bkmusic_condition = 2;
        all::operate_bkmusic();
    }
    if (begin_music_condition != 5 && begin_music_condition != 1)  //关闭菜单音乐
    {
        begin_music_condition = 0;
        all::operate_begin_music();
    }
    int m = 0;
    while (1) {
        m++;
        if (m > 1500000) {
            show();/////////////////显示
            dowithinput();///////////////处理输入信息
            dowithoutinput();////////////////处理游戏信息
            m = 0;
        }
    }
}

///////////////重力
void all::gravity() {
    no1.gravity();
}

///////////////移动
void all::move() {
    no1.move();
}

//////////////////关于静止物体
void all::staticobject() {
    bottom.nature(no1);
    for (int i = 0; i < floatearthnumber; i++) {
        floatearth[i].nature(no1);
    }
}

//////////////////////总的enemy函数集合
void all::allaboutenemy(player& name) {
    int i;
    nearboss = false;
    for (i = 0; i < 200; i++) {
        if(i < enemy1number - max((5 - Gamelevel) * 10, 0)) {
            if (fabs(enemy1[i].x - name.x) <= 700 && fabs(enemy1[i].y - name.y) <= 500 && enemy1[i].alive) {
                enemy1[i].closefight(name);
                enemy1[i].die(1);
                enemy1[i].show();
                enemy1[i].move();
                enemy1[i].gravity();
                enemy1[i].beattacked(no1);
                enemy1[i].showinfo();
                bottom.nature(enemy1[i]);

                skill_1.skill_hitenemy(&enemy1[i].x, &enemy1[i].y, &enemy1[i].blood);

                for (int j = 0; j < floatearthnumber; j++) {
                    floatearth[j].nature(enemy1[i]);
                    enemy1[i].walkback(floatearth[j]);
                }
            }
        }
        if(i < enemyshooter1number - max((5 - Gamelevel) * 5, 0)){
            if (fabs(enemyshooter1[i].x - name.x) <= 700 && fabs(enemyshooter1[i].y - name.y) <= 500 && enemyshooter1[i].alive) {
                enemyshooter1[i].closefight(name);
                enemyshooter1[i].die(2);
                enemyshooter1[i].show();
                enemyshooter1[i].move();
                enemyshooter1[i].gravity();
                enemyshooter1[i].beattacked(no1);
                bottom.nature(enemyshooter1[i]);
                enemyshooter1[i].showinfo();

                skill_1.skill_hitenemy(&enemyshooter1[i].x, &enemyshooter1[i].y, &enemyshooter1[i].blood);

                for (int j = 0; j < floatearthnumber; j++) {
                    floatearth[j].nature(enemyshooter1[i]);
                    enemyshooter1[i].walkback(floatearth[j]);
                }
                enemyshooter1[i].shot(name);
            }
        }
        if(i < enemystrong1number - fmax((5 - Gamelevel) * 2, 0)) {
            if (fabs(enemystrong1[i].x - name.x) <= 700 && fabs(enemystrong1[i].y - name.y) <= 500 && enemystrong1[i].alive) {
                enemystrong1[i].closefight(name);
                enemystrong1[i].die(3);
                enemystrong1[i].show();
                enemystrong1[i].move();
                enemystrong1[i].gravity();
                enemystrong1[i].beattacked(no1);

                enemystrong1[i].showinfo();

                skill_1.skill_hitenemy(&enemystrong1[i].x, &enemystrong1[i].y, &enemystrong1[i].blood);
                bottom.nature(enemystrong1[i]);
                for (int j = 0; j < floatearthnumber; j++) {
                    floatearth[j].nature(enemystrong1[i]);
                    enemystrong1[i].walkback(floatearth[j]);
                }
                enemystrong1[i].shot(name);
            }
        }
        if(i < fmin(Gamelevel, enemyboss1number)){
            if (fabs(enemyboss1[i].x - name.x) <= 1000 && fabs(enemyboss1[i].y - name.y) <= 800 && enemyboss1[i].alive) {
                enemyboss1[i].closefight(name);
                enemyboss1[i].die();
                enemyboss1[i].show();
                enemyboss1[i].move(no1);
                enemyboss1[i].beattacked(no1);

                enemyboss1[i].showinfo();


                skill_1.skill_hitenemy(&enemyboss1[i].x, &enemyboss1[i].y, &enemyboss1[i].blood);
                bottom.nature(enemyboss1[i]);
                enemyboss1[i].shot(name);
                nearboss = true;
            }
        }
    }
}

///////////////总的子弹函数集合
void all::allaboutbullet() {
    int i;
    for (i = 0; i < 2000; i++) {
        /// //////////////////move  and   show（放在同一个循环里，少许减少电脑压力）
        if (no1.bullet[i].exist) {
            no1.bullet[i].move();
            no1.bullet[i].show();
            no1.bullet[i].split();
        }
        if (bullet[i].exist) {
            bullet[i].move();
            bullet[i].show();
            bullet[i].hitplayer(no1);
        }
    }
}

/////////////////下一关，各种物品的复位
void all::nextlevel() {
    int i;
    no1.reset();
    Gamelevel++;
    door1.reset();
    for (i = 0; i < enemy1number; i++) {
        enemy1[i].reset();
    }
    for (i = 0; i < enemyshooter1number; i++) {
        enemyshooter1[i].reset();
    }
    for (i = 0; i < enemystrong1number; i++) {
        enemystrong1[i].reset();
    }
    for (i = 0; i < enemyboss1number; i++) {
        enemyboss1[i].reset();
    }
    for (i = 0; i < floatearthnumber; i++) {
        floatearth[i].reset();
    }
    for (i = 0; i < 2002; i++) {
        no1.bullet[i].exist = false;
        bullet[i].exist = false;
    }

}

/////////////////////玩家控制函数
void player::control() {
    if (::GetAsyncKeyState('D') & 0x8000 && canmove) {
        vx = 2;
    }
    if (::GetAsyncKeyState('W') & 0x8000) {
        if (flytime > 0) {
            flytime -= 2;
        }
        if (flytime >= 10) {
            vy = -3;
        }
    }
    static int g = 0;
    if (!canmove) {
        g++;
        if (g > 100) {
            canmove = true;
            g = 0;
        }
    }
    if (::GetAsyncKeyState('A') & 0x8000 && canmove) {
        vx = -2;
    }
}

/////////////////////////玩家状态栏显示函数
void player::showinfo(const graphfollow& name) {
    ////////////////////////////////////////blood
    setfillcolor(HSVtoRGB(1, 0, 0.5));
    fillrectangle(infox - name.x - 2, infoy - name.y - 2, infox - name.x + 300 + 2, infoy - name.y + 20 + 2);
    setfillcolor(HSVtoRGB(1, 1, 1));
    fillrectangle(infox - name.x, infoy - name.y, infox - name.x + 300 * blood / bloodmax, infoy - name.y + 20);
    /*
    setfillcolor(HSVtoRGB(1, 0, 0.5));
    fillrectangle(x - 40, y - 69, x + 40, y - 61);
    setfillcolor(HSVtoRGB(1, 1, 1));
    fillrectangle(x - 38, y - 68, x - 38 + blood / bloodmax * 76, y - 60);
    */
    ////////////////////////////////////////magic
    setfillcolor(HSVtoRGB(1, 0, 0.5));
    fillrectangle(infox - name.x - 2, infoy - name.y - 2 + 30, infox - name.x + 200 + 2, infoy - name.y + 30 + 10 + 2);
    setfillcolor(HSVtoRGB(220, 1, 1));
    fillrectangle(infox - name.x, infoy - name.y + 30, infox - name.x + 200 * magic / magicmax, infoy - name.y + 30 + 10);
    ////////////////////////////////////////flytime
    setfillcolor(HSVtoRGB(1, 0, 0.5));
    fillrectangle(infox - name.x - 2, infoy - name.y - 2 + 50, infox - name.x + 200 + 2, infoy - name.y + 50 + 10 + 2);
    setfillcolor(HSVtoRGB(200, 1, 1));
    fillrectangle(infox - name.x, infoy - name.y + 50, infox - name.x + 200 * flytime / flytimemax, infoy - name.y + 50 + 10);
    ////////////////////////////////////////experience
    setfillcolor(HSVtoRGB(1, 0, 0.5));
    fillrectangle(infox - name.x - 2, infoy - name.y - 2 + 70, infox - name.x + 200 + 2, infoy - name.y + 70 + 10 + 2);
    setfillcolor(HSVtoRGB(50, 1, 1));
    fillrectangle(infox - name.x, infoy - name.y + 70, infox - name.x + 200 * experience / (level * 100), infoy - name.y + 70 + 10);
    // /////////////////////////////////////attackenergy
    setfillcolor(HSVtoRGB(1, 0, 0.5));
    fillrectangle(x - 30, y - 60, x + 30, y - 50);
    setfillcolor(HSVtoRGB(50, 0.8, 0.7));
    fillrectangle(x - 28, y - 59, x - 28 + attackenergy / 900 * 56, y - 51);
    line(x - 10, y - 59, x - 10, y - 51);
    line(x + 10, y - 59, x + 10, y - 51);

}

//////////////////玩家状态函数
void player::condition() {
    if (blood < bloodmax - 0.05) {
        blood += bloodrecovery;
    }
    ///////////////飞行时间恢复
    if (flytime < flytimemax) {
        flytime += flytimerecovery;
    }
    ///////////////游戏结束
    if (blood <= 0) {
        all::gameover();
    }
    ////////////////升级
    if (experience >= level * 100) {
        experience -= level * 100;
        level++;
        bloodmax *= 1.2;
        magicmax *= 1.1;
        flytimemax *= 1.05;
        blood = bloodmax;
        magic = magicmax;
        bloodrecovery *= 1.1;
        attack *= 1.2;
        attackenergy = 900;
    }
    //////////////////攻击能量恢复
    if (attackenergy < 900) {
        attackenergy += 1;
    }
}

/////////////////玩家显示函数
void player::show() {

    static int m1 = 0;
    static int m2 = 0;
    static int i = 0;
    i++;
    if (i > 7) {
        i = 0;
        m1++;
        m2++;
    }
    if (m1 > 17) {
        m1 = 0;
    }
    if (m2 > 11) {
        m2 = 0;
    }
    /////////////////////向左向右步行动画
    /////////////////////向左向右站立动画
    if (no1.vx > 1) {
        putimagepng(x - 50, y - 40, &no1walk[m1]);
    }
    else if (no1.vx < -1) {
        putimagepng(x - 50, y - 40, &fno1walk[m1]);
    }
    else if (0 <= no1.vx && no1.vx < 1) {
        putimagepng(x - 50, y - 40, &no1stand[m2]);
    }
    else if (-1 < no1.vx && no1.vx <= 0) {
        putimagepng(x - 50, y - 40, &fno1stand[m2]);
    }

}

//////////////////鼠标修正页面
void Mouse::fixmouse(const graphfollow& name) {
    BeginBatchDraw();
    IMAGE pic1;
    loadimage(&pic1, _T("fixmouse04.jpg"), WIDTH, HEIGHT, TRUE);
    putimage(-name.x, -name.y, &pic1);
    putimage(-name.x - 24 + WIDTH / 2, -name.y - 25 + HEIGHT / 2, &scope1, MERGEPAINT);
    FlushBatchDraw();
    while (1) {
        SetConsoleTitleA("Get Cursor Postition");
        POINT pt;
        BOOL bReturn = GetCursorPos(&pt); //获取鼠标指针位置到pt
        setlinestyle(PS_SOLID, 3, NULL, 1);
        fixx = -pt.x + WIDTH / 2;///////////////////鼠标修正变量x的校准
        fixy = -pt.y + HEIGHT / 2;///////////////////鼠标修正变量y的校准
        if (::GetAsyncKeyState(VK_SPACE) & 0x8000) {
            break;//////////////校准完成  退出循环
        }
    }
    setlinestyle(PS_SOLID, 1, NULL, 1);
    setlinecolor(HSVtoRGB(0, 0, 1));
}

/////////////////////移动函数
void moveobject::move() {
    x += vx;
    y += vy;
}

////////////////////小球移动函数
void Bullet::move() {
    x += vx * v + xbegin;
    y += vy * v + ybegin;
    existtime++;
    if (existtime > 1000) {
        exist = false;
    }
}

///////////////////子弹显示函数
void Bullet::show() {
    fillcircle(x, y, 15);
}

/////////////////人物射击函数
void player::shot(const Mouse& name) {

    static int condition = 0;///////////人物射击操控方法（0.1.2）
    static int p = 0;

    int i = 0;
    static int g = 0;
    static int m = 0;
    static int j = 0;
    static int toshoot[10] = { 0 };
    static int c[10] = { 0 };
    static double bvx[10] = { 0 };
    static double bvy[10] = { 0 };
    static double x1 = 0;
    static double y1 = 0;
    static double degree = 0;

    if (p < 100) {
        p++;
    }
    ////////////////////按下空格切换操控状态
    if (::GetAsyncKeyState(VK_SPACE) & 0x8000 && p >= 100) {
        p = 0;
        condition++;
        condition = condition % 3;
    }
    /*
    static int m = 0;
    m++;
    if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000 && m > 10) {
        m = 0;
        bullet[no1bnum].xbegin = vx;
        bullet[no1bnum].ybegin = vy;
        bullet[no1bnum].x = x;
        bullet[no1bnum].y = y;
        bullet[no1bnum].vx = (name.x - x) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
        bullet[no1bnum].vy = (name.y - y) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
        bullet[no1bnum].exist = TRUE;
        bullet[no1bnum].existtime = 0;
        bullet[no1bnum].level = level;
        no1bnum++;
        if (no1bnum >= 2000) {
            no1bnum = 0;
        }
    }
    if (::GetAsyncKeyState('K') & 0x8000 && m > 10) {
        m = 0;
        bullet[no1bnum].xbegin = vx;
        bullet[no1bnum].ybegin = vy;
        bullet[no1bnum].x = x;
        bullet[no1bnum].y = y;
        bullet[no1bnum].vx = 1;
        bullet[no1bnum].vy = 0;
        bullet[no1bnum].exist = TRUE;
        bullet[no1bnum].existtime = 0;
        bullet[no1bnum].level = level;
        no1bnum++;
        if (no1bnum >= 2000) {
            no1bnum = 0;
        }
    }
    if (::GetAsyncKeyState('J') & 0x8000 && m > 10) {
        m = 0;
        bullet[no1bnum].xbegin = vx;
        bullet[no1bnum].ybegin = vy;
        bullet[no1bnum].x = x;
        bullet[no1bnum].y = y;
        bullet[no1bnum].vx = -1;
        bullet[no1bnum].vy = 0;
        bullet[no1bnum].exist = TRUE;
        bullet[no1bnum].existtime = 0;
        bullet[no1bnum].level = level;
        no1bnum++;
        if (no1bnum >= 2000) {
            no1bnum = 0;
        }
    }
    */
    ////////////////第三种状态，纯键盘，
    if (condition == 2) {
        line(x, y, x + 800 * cos(degree), y + 800 * sin(degree));

        if (::GetAsyncKeyState('L') & 0x8000) {
            degree += 0.01;
        }
        if (::GetAsyncKeyState('J') & 0x8000) {
            degree -= 0.01;
        }
        if (j <= 50) {
            j++;
        }
        if (::GetAsyncKeyState('K') & 0x8000 && j > 50 && attackenergy >= 300) {
            j = 0;
            attackenergy -= 300;
            for (i = 0; i < 10; i++) {
                if (toshoot[i] <= 0) {
                    toshoot[i] = 10;
                    bvx[i] = cos(degree);
                    bvy[i] = sin(degree);
                    break;
                }
            }
        }
        if (g < 10) {
            g++;
        }
        if (g >= 10) {
            g = 0;
            for (i = 0; i < 10; i++) {
                if (toshoot[i] > 0) {
                    toshoot[i]--;
                    bullet[no1bnum].xbegin = vx;
                    bullet[no1bnum].ybegin = vy;
                    bullet[no1bnum].x = x;
                    bullet[no1bnum].y = y;

                    bullet[no1bnum].vx = bvx[i];
                    bullet[no1bnum].vy = bvy[i];

                    bullet[no1bnum].exist = TRUE;
                    bullet[no1bnum].existtime = 0;
                    bullet[no1bnum].level = level;
                    no1bnum++;
                    if (no1bnum >= 2000) {
                        no1bnum = 0;
                    }
                }
            }
        }

    }

    ///////////////第二种状态，、
    if (condition == 1) {
        circle(x1 - graph.x, y1 - graph.y, 100);
        fillcircle(name.x, name.y, 30);
        line(x, y, 800 * (name.x - x1 + graph.x) / pow(pow(name.x - x1 + graph.x, 2) + pow(name.y - y1 + graph.y, 2), 0.5) + x, 800 * (name.y - y1 + graph.y) / pow(pow(name.x - x1 + graph.x, 2) + pow(name.y - y1 + graph.y, 2), 0.5) + y);
        if (m <= 100) {
            m++;
        }
        if (::GetAsyncKeyState(VK_RBUTTON) & 0x8000 && m > 100) {
            x1 = name.x + graph.x;
            y1 = name.y + graph.y;
        }
        if (j < 50) {
            j++;
        }
        if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000 && j >= 50 && attackenergy >= 300) {
            j = 0;
            attackenergy -= 300;
            for (i = 0; i < 10; i++) {
                if (toshoot[i] <= 0) {
                    toshoot[i] = 10;
                    bvx[i] = (name.x - x1 + graph.x) / pow(pow(name.x - x1 + graph.x, 2) + pow(name.y - y1 + graph.y, 2), 0.5);
                    bvy[i] = (name.y - y1 + graph.y) / pow(pow(name.x - x1 + graph.x, 2) + pow(name.y - y1 + graph.y, 2), 0.5);
                    break;
                }
            }
        }
        if (g < 10) {
            g++;
        }
        if (g >= 10) {
            g = 0;
            for (i = 0; i < 10; i++) {
                if (toshoot[i] > 0) {
                    toshoot[i]--;
                    bullet[no1bnum].xbegin = vx;
                    bullet[no1bnum].ybegin = vy;
                    bullet[no1bnum].x = x;
                    bullet[no1bnum].y = y;

                    bullet[no1bnum].vx = (name.x - x1 + graph.x) / pow(pow(name.x - x1 + graph.x, 2) + pow(name.y - y1 + graph.y, 2), 0.5);
                    bullet[no1bnum].vy = (name.y - y1 + graph.y) / pow(pow(name.x - x1 + graph.x, 2) + pow(name.y - y1 + graph.y, 2), 0.5);

                    bullet[no1bnum].exist = TRUE;
                    bullet[no1bnum].existtime = 0;
                    bullet[no1bnum].level = level;
                    no1bnum++;
                    if (no1bnum >= 2000) {
                        no1bnum = 0;
                    }
                }
            }
        }

    }

    ////////////////////第一种状态
    if (condition == 0) {
        line(x, y, 800 * (name.x - x) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5) + x, 800 * (name.y - y) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5) + y);
        if (m <= 100) {
            m++;
        }
        if (j <= 10) {
            j++;
        }
        if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000 && m >= 50 && attackenergy >= 300) {
            m = 0;
            attackenergy -= 300;
            for (i = 0; i < 10; i++) {
                if (toshoot[i] <= 0) {
                    toshoot[i] = 10;
                    c[i] = 1;
                    break;
                }
            }
        }
        if (::GetAsyncKeyState('J') & 0x8000 && m >= 50 && attackenergy >= 300) {
            m = 0;
            attackenergy -= 300;
            for (i = 0; i < 10; i++) {
                if (toshoot[i] <= 0) {
                    toshoot[i] = 10;
                    c[i] = 2;
                    break;
                }
            }
        }
        if (::GetAsyncKeyState('K') & 0x8000 && m >= 50 && attackenergy >= 300) {
            m = 0;
            attackenergy -= 300;
            for (i = 0; i < 10; i++) {
                if (toshoot[i] <= 0) {
                    toshoot[i] = 10;
                    c[i] = 3;
                    break;
                }
            }
        }
        if (j >= 10) {
            j = 0;
            for (i = 0; i < 10; i++) {
                if (toshoot[i] > 0) {
                    toshoot[i]--;
                    bullet[no1bnum].xbegin = vx;
                    bullet[no1bnum].ybegin = vy;
                    bullet[no1bnum].x = x;
                    bullet[no1bnum].y = y;
                    if (c[i] == 1) {
                        bullet[no1bnum].vx = (name.x - x) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
                        bullet[no1bnum].vy = (name.y - y) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
                    }
                    else if (c[i] == 2) {
                        bullet[no1bnum].vx = -1;
                        bullet[no1bnum].vy = 0;
                    }
                    else if (c[i] == 3) {
                        bullet[no1bnum].vx = 1;
                        bullet[no1bnum].vy = 0;
                    }
                    bullet[no1bnum].exist = TRUE;
                    bullet[no1bnum].existtime = 0;
                    bullet[no1bnum].level = level;
                    no1bnum++;
                    if (no1bnum >= 2000) {
                        no1bnum = 0;
                    }
                }
            }
        }
    }

}

/////////enemy近战函数
void enemy::closefight(player& name) {
    if ( fabs(x - name.x) < volum+name.volum && fabs(y - name.y) < volum+name.volum) {
        name.blood -= closefightdamage;
        name.canmove = false;
        ////////////////把人物弹开，并短时间内无法移动，防止血量瞬间被卡没
        if (x <= name.x) {
            vx *= 0.5;
            name.x += 45;
            name.vx = fabs(name.vx);
            vy = -vy;
        }
        else if (x > name.x) {
            vx *= 0.5;
            name.x -= 45;
            name.vx = -fabs(name.vx);
            vy = -vy;
        }
    }
}

///////////enemy行走函数
void enemy::walkback(const ground& name) {
    ///////////////////如果走到边界，自动折返
    if (name.x <= x && x < name.x + 5 && name.y - 1 < y+volum && y+volum < name.y + 1) {
        x = name.x + 5;
        vx = fabs(vx);
    }
    if (name.x + name.length - 5 < x && x <= name.x + name.length && name.y - 1 < y+volum && y+volum < name.y + 1) {
        x = name.x + name.length - 5;
        vx = -fabs(vx);
    }
}

///////////////enemyshooter的射击函数
void enemyshooter::shot(const player& name) {
    ///////////////shootime用来控制射击频率
    shoottime++;
    if (fabs(x - name.x) <= 400 && fabs(y - name.y) <= 200 && shoottime > 200) {

        shoottime = 0;
        bullet[bnum].v = 0.7;
        bullet[bnum].x = x;
        bullet[bnum].y = y;
        bullet[bnum].vx = (name.x - x) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
        bullet[bnum].vy = (name.y - y) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
        bullet[bnum].existtime = 0;
        bullet[bnum].exist = TRUE;
        bnum++;
        if (bnum >= 2000) {
            bnum = 0;
        }
    }
}

////////////enemy被攻击函数
void enemy::beattacked(player& name) {
    int i;
    for (i = 0; i < 2000; i++) {
        if (name.bullet[i].exist && fabs(name.bullet[i].x - x) < volum + 15 && fabs(name.bullet[i].y - y) < volum + 15) {
            name.bullet[i].exist = false;
            blood -= name.attack;
            if (name.bullet[i].x <= x) {
                x += 4;
            }
            else {
                x -= 4;
            }
        }
    }
}

////////////////成功通过门函数
void door::succeed(const player& name) {
    if (name.havekey && x <= name.x && name.x < x + 40 && y - 200 <= name.y && name.y < y) {
        all::nextlevel();//////////////下一关
    }
}

//////////////////////////////人物被enemy子弹攻击函数
void Bullet::hitplayer(player& name) {
    if (fabs(name.x - x) < 10 && fabs(name.y - y) < 10) {
        exist = false;//////子弹消失
        name.blood -= enemyshooter1[0].shootdamdge;
    }
}

//////////////////enemystrong射击函数
void enemystrong::shot(const player& name) {
    shoottime++;
    static int m = 0;
    if (fabs(x - name.x) <= 400 && fabs(y - name.y) <= 300 && shoottime > 200) {
        m++;
        shoottime = 0;
        bullet[bnum].v = 0.7;
        bullet[bnum].x = x;
        bullet[bnum].y = y;
        bullet[bnum].vx = (name.x - x) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
        bullet[bnum].vy = (name.y - y) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
        bullet[bnum].existtime = 0;
        bullet[bnum].exist = TRUE;
        bnum++;
        if (bnum >= 2000) {
            bnum = 0;
        }
        ///////////////////////////////这里是strong特头的射击效果，全方位散射一次
        if (m >= 10) {
            m = 0;
            for (int i = 0; i < 20; i++) {
                bullet[bnum].existtime = 0;
                bullet[bnum].v = 0.7;
                bullet[bnum].x = x;
                bullet[bnum].y = y;
                bullet[bnum].vx = cos(3.14159 / 10 * i);
                bullet[bnum].vy = sin(3.14159 / 10 * i);
                bullet[bnum].existtime = 0;
                bullet[bnum].exist = TRUE;
                bnum++;
                if (bnum >= 2000) {
                    bnum = 0;
                }
            }
        }
    }
}

////////////////enemyboss的射击函数
void enemyboss::shot(const player& name) {
    shoottime++;
    static int m = 0;
    static int j = 0;
    static int q = 0;
    if (fabs(x - name.x) <= 900 && fabs(y - name.y) <= 600 && shoottime > 150 - 120 * (bloodmax - blood) / bloodmax) {
        m++;
        shoottime = 0;
        bullet[bnum].v = 0.7;
        bullet[bnum].x = x;
        bullet[bnum].y = y;
        bullet[bnum].vx = (name.x - x) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
        bullet[bnum].vy = (name.y - y) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
        bullet[bnum].existtime = 0;
        bullet[bnum].exist = TRUE;
        bnum++;
        if (bnum >= 2000) {
            bnum = 0;
        }
        if (m >= 10) {
            m = 0;
            j = 15;
        }
    }
    //////////////////////这是boss特有的函数，全方位旋转散射n次
    if (q <= 20) {
        q++;
    }
    if (j > 0 && q > 20) {
        q = 0;
        j--;
        for (int i = 0; i < 20; i++) {
            bullet[bnum].existtime = 0;
            bullet[bnum].v = 0.7;
            bullet[bnum].x = x;
            bullet[bnum].y = y;
            bullet[bnum].vx = cos(3.14159 / 10 * i + 3.14159 / 50 * j);
            bullet[bnum].vy = sin(3.14159 / 10 * i + 3.14159 / 50 * j);
            bullet[bnum].existtime = 0;
            bullet[bnum].exist = TRUE;
            bnum++;
            if (bnum >= 2000) {
                bnum = 0;
            }
        }
    }
}

/////////////////////////enemyboss移动 不受平台限制
void enemyboss::move(const player& name) {
    if (fabs(name.x - x) < 600 && fabs(name.y - y) < 400) {
        x += 0.5 * (name.x - x) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
        y += 0.5 * (name.y - y) / pow(pow(name.x - x, 2) + pow(name.y - y, 2), 0.5);
    }
}

//////////////////////获得钥匙函数
void key::getkey(player& name) {
    if (exist && fabs(name.x - x) < 30 && fabs(name.y - y) < 30) {
        name.havekey = true;
        exist = false;
    }
}

//////////////////////子弹分裂函数，人物等级高了，射出的子弹可以分裂
void Bullet::split() {
    if (level > 2 && existtime % (50 / min(level / 2, 3)) == 0 && existtime < 50) {
        no1.bullet[no1bnum].x = x + 15 * vy;
        no1.bullet[no1bnum].y = y + 15 * vx;
        x -= 5 * vy;
        y -= 5 * vx;
        no1.bullet[no1bnum].xbegin = xbegin;
        no1.bullet[no1bnum].ybegin = ybegin;
        no1.bullet[no1bnum].v = v;
        no1.bullet[no1bnum].vx = vx;
        no1.bullet[no1bnum].vy = vy;
        no1.bullet[no1bnum].exist = TRUE;
        no1.bullet[no1bnum].existtime = existtime;
        no1bnum++;
        if (no1bnum >= 2000) {
            no1bnum = 0;
        }
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void time_loading()
{
    loading3.radius_basis = 14;
    loading3.radius_total = 100;
    loading3.difference = 1;
    int count_time = 1;
    while (1)
    {
        BeginBatchDraw();
        cleardevice();

        loading1.draw(600, 300);
        loading3.draw(600, 300);

        TCHAR str[20]; // 定义字符数组
        swprintf_s(str, _T("Loading...")); //转换为字符串
        settextstyle(30, 0, _T("Arials"));
        setbkmode(TRANSPARENT); // 透明显示文字
        settextcolor(WHITE);  // 设置字体颜色
        outtextxy(530, 270, str); // 输出文字


        FlushBatchDraw();

        count_time++;
        if (count_time > 3000)//退出循环
            break;
    }

}

///////////////////////////////////暂停页面
void all::pause() {

    while (1) {
        BeginBatchDraw();
        cleardevice();
        mouse.getmouse(graph);
        putimage(-graph.x, -graph.y, &pause1);
        ///////////////////下面为鼠标放到按键上后的动画效果
        if (400 - graph.x <= mouse.x && mouse.x <= 800 - graph.x && 40 - graph.y <= mouse.y && mouse.y <= 140 - graph.y) {
            putimage(-graph.x + 380, -graph.y + 35, &jxyx2);
            putimage(-graph.x + 400, -graph.y + 180, &fhcd1);
            putimage(-graph.x + 400, -graph.y + 320, &sz1);
            putimage(-graph.x + 400, -graph.y + 460, &tc1);
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                break;///////////继续
            }
        }
        else if (400 - graph.x <= mouse.x && mouse.x <= 800 - graph.x && 180 - graph.y <= mouse.y && mouse.y <= 280 - graph.y) {
            putimage(-graph.x + 400, -graph.y + 40, &jxyx1);
            putimage(-graph.x + 380, -graph.y + 175, &fhcd2);
            putimage(-graph.x + 400, -graph.y + 320, &sz1);
            putimage(-graph.x + 400, -graph.y + 460, &tc1);
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                storedata();    //自动存档
                mciSendString(_T("pause bk_music"), NULL, 0, NULL);    //暂停播放背景音乐
                all::menu();    //返回主菜单
            }
        }
        else if (400 - graph.x <= mouse.x && mouse.x <= 800 - graph.x && 320 - graph.y <= mouse.y && mouse.y <= 420 - graph.y) {
            putimage(-graph.x + 400, -graph.y + 40, &jxyx1);
            putimage(-graph.x + 400, -graph.y + 180, &fhcd1);
            putimage(-graph.x + 380, -graph.y + 315, &sz2);
            putimage(-graph.x + 400, -graph.y + 460, &tc1);
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                all::settings();////////////////设置
            }
        }
        else if (400 - graph.x <= mouse.x && mouse.x <= 800 - graph.x && 460 - graph.y <= mouse.y && mouse.y <= 560 - graph.y) {
            putimage(-graph.x + 400, -graph.y + 40, &jxyx1);
            putimage(-graph.x + 400, -graph.y + 180, &fhcd1);
            putimage(-graph.x + 400, -graph.y + 320, &sz1);
            putimage(-graph.x + 380, -graph.y + 455, &tc2);
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                storedata();////////////存档
                exit(0);//////////////退出
            }
        }
        else {
            putimage(-graph.x + 400, -graph.y + 40, &jxyx1);
            putimage(-graph.x + 400, -graph.y + 180, &fhcd1);
            putimage(-graph.x + 400, -graph.y + 320, &sz1);
            putimage(-graph.x + 400, -graph.y + 460, &tc1);
        }
        FlushBatchDraw();
    }

}

///////////////////////////菜单界面函数
void all::menu() {
    int m = 0;
    int n = 200;

    if (bkmusic_condition != 5 && bkmusic_condition != 1) //关闭游戏音乐
    {
        bkmusic_condition = 0;
        all::operate_bkmusic();
    }
    if (begin_music_condition != 5 && begin_music_condition != 3)  //打开菜单音乐
    {
        begin_music_condition = 2;
        all::operate_begin_music();
    }
    while (1) {
        if (m < n)
            m++;
        BeginBatchDraw();
        cleardevice();
        mouse.getmouse(graph);
        putimage(-graph.x, -graph.y, &pause1);
        ///////////////////下面为鼠标放到按键上后的动画效果
        if (458 - graph.x <= mouse.x && mouse.x <= 742 - graph.x && 320 - graph.y <= mouse.y && mouse.y <= 370 - graph.y && m == n) {
            putimage(-graph.x + 444, -graph.y + 317.5, &menuxyx2, SRCAND);
            putimage(-graph.x + 458, -graph.y + 390, &menudq1, SRCPAINT);
            putimage(-graph.x + 458, -graph.y + 460, &menusz1, SRCPAINT);
            putimage(-graph.x + 458, -graph.y + 530, &menuds1, SRCPAINT);
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                all::restart();////////////////初始化
                all::battle();/////////////////战斗
            }
        }
        else if (458 - graph.x <= mouse.x && mouse.x <= 742 - graph.x && 390 - graph.y <= mouse.y && mouse.y <= 440 - graph.y && m == n) {
            putimage(-graph.x + 458, -graph.y + 320, &menuxyx1, SRCPAINT);
            putimage(-graph.x + 444, -graph.y + 387.5, &menudq2, SRCINVERT);
            putimage(-graph.x + 458, -graph.y + 460, &menusz1, SRCPAINT);
            putimage(-graph.x + 458, -graph.y + 530, &menuds1, SRCPAINT);
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                readdata();/////////////读档
                all::battle();/////////////////战斗
            }
        }
        else if (458 - graph.x <= mouse.x && mouse.x <= 742 - graph.x && 460 - graph.y <= mouse.y && mouse.y <= 510 - graph.y && m == n) {
            putimage(-graph.x + 458, -graph.y + 320, &menuxyx1, SRCPAINT);
            putimage(-graph.x + 458, -graph.y + 390, &menudq1, SRCPAINT);
            putimage(-graph.x + 444, -graph.y + 457.5, &menusz2, SRCERASE);
            putimage(-graph.x + 458, -graph.y + 530, &menuds1, SRCPAINT);
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                all::settings();/////////////////设置
            }
        }
        else if (458 - graph.x <= mouse.x && mouse.x <= 742 - graph.x && 530 - graph.y <= mouse.y && mouse.y <= 580 - graph.y && m == n) {
            putimage(-graph.x + 458, -graph.y + 320, &menuxyx1, SRCPAINT);
            putimage(-graph.x + 458, -graph.y + 390, &menudq1, SRCPAINT);
            putimage(-graph.x + 458, -graph.y + 460, &menusz1, SRCPAINT);
            putimage(-graph.x + 444, -graph.y + 527.5, &menuds2, SRCERASE);

        }
        else {     //鼠标不在选项区域内时，所有选项以原来大小存在。
            putimage(-graph.x + 458, -graph.y + 320, &menuxyx1, SRCPAINT);
            putimage(-graph.x + 458, -graph.y + 390, &menudq1, SRCPAINT);
            putimage(-graph.x + 458, -graph.y + 460, &menusz1, SRCPAINT);
            putimage(-graph.x + 458, -graph.y + 530, &menuds1, SRCPAINT);
        }
        FlushBatchDraw();
    }

}

/////////////////////设置页面
void all::settings()
{


    int m = 0;  //音乐按键控制间隔按下变量
    int r = 0;  //返回按键控制间隔按下变量
    int f = 0;  //校准按钮。。。。
    while (1)
    {

        if (m < 200) {
            m++;
        }
        if (r < 200)
            r++;
        if (f < 200)
            f++;

        BeginBatchDraw();
        cleardevice();   //清屏
        mouse.getmouse(graph);

        //音乐开关控制
        static int music_con = 0;
        putimage(-graph.x, -graph.y, &pause1);

        if (music_con % 2 == 0)  //音乐处于打开状态
            putimage(-graph.x + 100, -graph.y + 100, &music_on);
        else if (music_con % 2 != 0)  //音乐处于关闭状态
            putimage(-graph.x + 100, -graph.y + 100, &music_off);

        if (100 - graph.x <= mouse.x && mouse.x <= 175 - graph.x && 100 - graph.y <= mouse.y && mouse.y <= 175 - graph.y) {  //获取鼠标位置
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000 && m >= 200) {
                music_con++;
                m = 0;
                if (music_con % 2 == 0)  //音乐处于打开状态
                {
                    putimage(-graph.x + 100, -graph.y + 100, &music_on);
                    bkmusic_condition = 2;    //取消静音状态
                    begin_music_condition = 0;
                }
                else if (music_con % 2 != 0)  //音乐处于关闭状态
                {
                    putimage(-graph.x + 100, -graph.y + 100, &music_off);
                    bkmusic_condition = 5;//静音状态
                    begin_music_condition = 5;
                }
                all::operate_begin_music();
                all::operate_bkmusic();
            }
        }

        if (music_con >= 10)   //控制music_con不要过大
        {
            music_con = 0;
        }

        //校准按键
        putimage(-graph.x + 100, -graph.y + 200, &focusmouse_button);
        if (100 - graph.x <= mouse.x && mouse.x <= 175 - graph.x && 200 - graph.y <= mouse.y && mouse.y <= 275 - graph.y) {  //获取鼠标位置
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000 && f >= 200) {

                f = 0;
                mouse.fixmouse(graph);
            }
        }

        //返回键
        putimage(-graph.x + 900, -graph.y + 300, &return_button);  //显示返回键按钮的图像
        if (900 - graph.x <= mouse.x && mouse.x <= 1100 - graph.x && 300 - graph.y <= mouse.y && mouse.y <= 375 - graph.y) {  //获取鼠标位置
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000 && r >= 200) {
                r = 0;
                break;
            }
        }



        FlushBatchDraw();
    }
}


///////////////////透明通道二号，未使用
void all::drawAlpha(IMAGE* picture, int  picture_x, int picture_y) //x为载入图片的X坐标，y为Y坐标
{

    // 变量初始化
    DWORD* dst = GetImageBuffer();    // GetImageBuffer()函数，用于获取绘图设备的显存指针，EASYX自带
    DWORD* draw = GetImageBuffer();
    DWORD* src = GetImageBuffer(picture); //获取picture的显存指针
    int picture_width = picture->getwidth(); //获取picture的宽度，EASYX自带
    int picture_height = picture->getheight(); //获取picture的高度，EASYX自带
    int graphWidth = getwidth();       //获取绘图区的宽度，EASYX自带
    int graphHeight = getheight();     //获取绘图区的高度，EASYX自带
    int dstX = 0;    //在显存里像素的角标

    // 实现透明贴图 公式： Cp=αp*FP+(1-αp)*BP ， 贝叶斯定理来进行点颜色的概率计算
    for (int iy = 0; iy < picture_height; iy++)
    {
        for (int ix = 0; ix < picture_width; ix++)
        {
            int srcX = ix + iy * picture_width; //在显存里像素的角标
            int sa = ((src[srcX] & 0xff000000) >> 24); //0xAArrggbb;AA是透明度
            int sr = ((src[srcX] & 0xff0000) >> 16); //获取RGB里的R
            int sg = ((src[srcX] & 0xff00) >> 8);   //G
            int sb = src[srcX] & 0xff;              //B
            if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight)
            {
                dstX = (ix + picture_x) + (iy + picture_y) * graphWidth; //在显存里像素的角标
                int dr = ((dst[dstX] & 0xff0000) >> 16);
                int dg = ((dst[dstX] & 0xff00) >> 8);
                int db = dst[dstX] & 0xff;
                draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16)  //公式： Cp=αp*FP+(1-αp)*BP  ； αp=sa/255 , FP=sr , BP=dr
                    | ((sg * sa / 255 + dg * (255 - sa) / 255) << 8)         //αp=sa/255 , FP=sg , BP=dg
                    | (sb * sa / 255 + db * (255 - sa) / 255);              //αp=sa/255 , FP=sb , BP=db
            }
        }
    }
}




void all::play_mainmenu_music()
{
    mciSendString(_T("play begin_music repeat"), NULL, 0, NULL);    //循环播放
}

void all::play_bkmusic()
{
    mciSendString(_T("stop begin_music"), NULL, 0, NULL);    //暂停播放菜单背景音乐
    mciSendString(_T("play bk_music repeat"), NULL, 0, NULL);    //循环播放
}

void all::operate_bkmusic()  //游戏背景音乐控制
{
    if (bkmusic_condition == 0)
    {
        mciSendString(_T("pause bk_music"), NULL, 0, NULL);    //暂停播放游戏背景音乐
        bkmusic_condition++;  //锁定
    }
    else if (bkmusic_condition == 2)
    {
        mciSendString(_T("play bk_music repeat"), NULL, 0, NULL);    //循环播放
        bkmusic_condition++;  //锁定
    }
    else if (bkmusic_condition == 5)
    {
        mciSendString(_T("pause bk_music"), NULL, 0, NULL);    //暂停播放游戏背景音乐
    }
}

void all::operate_begin_music()  //菜单背景音乐控制
{
    if (begin_music_condition == 0)
    {
        mciSendString(_T("pause begin_music"), NULL, 0, NULL);    //暂停播放菜单背景音乐
        begin_music_condition++;  //锁定
    }
    else if (begin_music_condition == 2)
    {
        mciSendString(_T("play begin_music repeat"), NULL, 0, NULL);    //循环播放
        begin_music_condition++;  //锁定
    }
    else if (begin_music_condition == 5)
    {
        mciSendString(_T("pause begin_music"), NULL, 0, NULL);    //暂停播放菜单背景音乐
    }
}

///////////////////初始化函数
void all::restart() {
    int i;
    money_amount = 0;
    no1.newgame();
    Gamelevel = 1;
    no1.level = 1;
    door1.reset();
    for (i = 0; i < enemy1number; i++) {
        enemy1[i].newgame();
    }
    for (i = 0; i < enemyshooter1number; i++) {
        enemyshooter1[i].newgame();
    }
    for (i = 0; i < enemystrong1number; i++) {
        enemystrong1[i].newgame();
    }
    for (i = 0; i < enemyboss1number; i++) {
        enemyboss1[i].newgame();
    }
    for (i = 0; i < floatearthnumber; i++) {
        floatearth[i].reset();
    }
    for (i = 0; i < 2002; i++) {
        no1.bullet[i].exist = false;
        bullet[i].exist = false;
    }
}

//////////////////////////存档函数
void storedata() {
    int i = 0;
    FILE* fp;
    fopen_s(&fp, "Data.txt", "w+");

    fprintf(fp, "%d\n", HistoricalGamelevel);

    key1.storedata(fp);
    key2.storedata(fp);

    for (i = 0; i < 3000; i++) {
        if (i < 2002) {
            bullet[i].storedata(fp);
            no1.bullet[i].storedata(fp);
        }
        if (i < enemy1number) {
            enemy1[i].storedata(fp);
        }
        if (i < enemyshooter1number) {
            enemyshooter1[i].storedata(fp);
        }
        if (i < enemystrong1number) {
            enemystrong1[i].storedata(fp);
        }
        if (i < enemyboss1number) {
            enemyboss1[i].storedata(fp);
        }
        if (i < floatearthnumber) {
            floatearth[i].storedata(fp);
        }
    }

    fprintf(fp, "%d\n", no1bnum);
    fprintf(fp, "%d\n", bnum);
    fprintf(fp, "%d\n", Gamelevel);
    fprintf(fp, "%d\n", money_amount);
    //bottom.storedata(fp);
    graph.storedata(fp);
    door1.storedata(fp);
    skill_1.storedata(fp);

    fclose(fp);
}

/////////////////////读档函数
void readdata() {
    int i = 0;
    FILE* fp;
    fopen_s(&fp, "Data.txt", "r");

    fscanf_s(fp, "%d", &HistoricalGamelevel);

    key1.readdata(fp);
    key2.readdata(fp);

    for (i = 0; i < 3000; i++) {
        if (i < 2002) {
            bullet[i].readdata(fp);
            no1.bullet[i].readdata(fp);
        }
        if (i < enemy1number) {
            enemy1[i].readdata(fp);
        }
        if (i < enemyshooter1number) {
            enemyshooter1[i].readdata(fp);
        }
        if (i < enemystrong1number) {
            enemystrong1[i].readdata(fp);
        }
        if (i < enemyboss1number) {
            enemyboss1[i].readdata(fp);
        }
        if (i < floatearthnumber) {
            floatearth[i].readdata(fp);
        }
    }

    fscanf_s(fp, "%d", &no1bnum);
    fscanf_s(fp, "%d", &bnum);
    fscanf_s(fp, "%d", &Gamelevel);
    fscanf_s(fp, "%d", &money_amount);
    //bottom.readdata(fp);
    graph.readdata(fp);
    door1.readdata(fp);
    skill_1.readdata(fp);

    fclose(fp);
}

////////////////////////////以下各个类里的存读档函数
void key::storedata(FILE* fp) {
    fprintf(fp, "%lf\n%lf\n%d\n", x, y, exist);
}

void key::readdata(FILE* fp) {
    fscanf_s(fp, "%lf%lf%d", &x, &y, &exist);
}


void Bullet::storedata(FILE* fp) {
    fprintf(fp, "%lf\n%lf\n", x, y);
    fprintf(fp, "%d\n%lf\n%lf\n%lf\n%lf\n%lf\n&d\n%d\n", level, xbegin, ybegin, vx, vy, v, existtime, exist);
}

void Bullet::readdata(FILE* fp) {
    fscanf_s(fp, "%lf%lf", &x, &y);
    fscanf_s(fp, "%d%lf%lf%lf%lf%lf&d%d", &level, &xbegin, &ybegin, &vx, &vy, &v, &existtime, &exist);
}

void player::storedata(FILE* fp) {
    fprintf(fp, "%lf\n%lf\n%lf\n%lf\n%lf\n", bloodrecovery, magic, magicmax, flytime, flytimemax);
    fprintf(fp, "%lf\n%lf\n%lf\n%lf\n%lf\n", flytimerecovery, experience, infox, infoy, attack);
    fprintf(fp, "%d\n%d\n", canmove, havekey);
    fprintf(fp, "%lf\n%lf\n%lf\n%lf\n%lf\n%lf\n%lf\n", blood, bloodmax, level, vx, vy, x, y);
}

void player::readdata(FILE* fp) {
    fscanf_s(fp, "%lf%lf%lf%lf%lf", &bloodrecovery, &magic, &magicmax, &flytime, &flytimemax);
    fscanf_s(fp, "%lf%lf%lf%lf%lf", &flytimerecovery, &experience, &infox, &infoy, &attack);
    fscanf_s(fp, "%d%d", &canmove, &havekey);
    fscanf_s(fp, "%lf%lf%lf%lf%lf%lf%lf", &blood, &bloodmax, &level, &vx, &vy, &x, &y);
}

void enemy::storedata(FILE* fp) {
    fprintf(fp, "%lf\n%lf\n%lf\n%lf\n%lf\n", vx, vy, blood, bloodmax, level);
    fprintf(fp, "%d\n%lf\n%lf\n%lf\n", alive, closefightdamage, exe, volum);
    fprintf(fp, "%lf\n%lf\n", x, y);
}
void enemy::readdata(FILE* fp) {
    fscanf_s(fp, "%lf%lf%lf%lf%lf", &vx, &vy, &blood, &bloodmax, &level);
    fscanf_s(fp, "%d%lf%lf%lf", &alive, &closefightdamage, &exe, &volum);
    fscanf_s(fp, "%lf%lf", &x, &y);
}

void enemyshooter::storedata(FILE* fp) {
    fprintf(fp, "&lf\n%lf\n", shoottime, shootdamdge);
    fprintf(fp, "%lf\n%lf\n%lf\n%lf\n%lf\n", vx, vy, blood, bloodmax, level);
    fprintf(fp, "%d\n%lf\n%lf\n%lf\n", alive, closefightdamage, exe, volum);
    fprintf(fp, "%lf\n%lf\n", x, y);
}

void enemyshooter::readdata(FILE* fp) {
    fscanf_s(fp, "&lf%lf", &shoottime, &shootdamdge);
    fscanf_s(fp, "%lf%lf%lf%lf%lf", &vx, &vy, &blood, &bloodmax, &level);
    fscanf_s(fp, "%d%lf%lf%lf", &alive, &closefightdamage, &exe, &volum);
    fscanf_s(fp, "%lf%lf", &x, &y);
}
void enemystrong::storedata(FILE* fp) {
    fprintf(fp, "&lf\n%lf\n", shoottime, shootdamdge);
    fprintf(fp, "%lf\n%lf\n%lf\n%lf\n%lf\n", vx, vy, blood, bloodmax, level);
    fprintf(fp, "%d\n%lf\n%lf\n%lf\n", alive, closefightdamage, exe, volum);
    fprintf(fp, "%lf\n%lf\n", x, y);
}
void enemystrong::readdata(FILE* fp) {
    fscanf_s(fp, "%lf%lf", &shoottime, &shootdamdge);
    fscanf_s(fp, "%lf%lf%lf%lf%lf", &vx, &vy, &blood, &bloodmax, &level);
    fscanf_s(fp, "%d%lf%lf%lf", &alive, &closefightdamage, &exe, &volum);
    fscanf_s(fp, "%lf%lf", &x, &y);
}

void enemyboss::storedata(FILE* fp) {
    fprintf(fp, "&lf\n%lf\n", shoottime, shootdamdge);
    fprintf(fp, "%lf\n%lf\n%lf\n%lf\n%lf\n", vx, vy, blood, bloodmax, level);
    fprintf(fp, "%d\n%lf\n%lf\n%lf\n", alive, closefightdamage, exe, volum);
    fprintf(fp, "%lf\n%lf\n", x, y);
}

void enemyboss::readdata(FILE* fp) {
    fscanf_s(fp, "%lf%lf", &shoottime, &shootdamdge);
    fscanf_s(fp, "%lf%lf%lf%lf%lf", &vx, &vy, &blood, &bloodmax, &level);
    fscanf_s(fp, "%d%lf%lf%lf", &alive, &closefightdamage, &exe, &volum);
    fscanf_s(fp, "%lf%lf", &x, &y);
}

void ground::storedata(FILE* fp) {
    fprintf(fp, "%lf\n%lf\n%lf\n%lf\n", height, length, x, y);
}

void ground::readdata(FILE* fp) {
    fscanf_s(fp, "%lf%lf%lf%lf", &height, &length, &x, &y);
}

void graphfollow::storedata(FILE* fp) {
    fprintf(fp, "%lf\n%lf\n%lf\n%lf\n%lf\n%lf\n", x, y, targetx, targety, movex, movey);
}

void graphfollow::readdata(FILE* fp) {
    fscanf_s(fp, "%lf%lf%lf%lf%lf%lf", &x, &y, &targetx, &targety, &movex, &movey);
}

void door::storedata(FILE* fp) {
    fprintf(fp, "%lf\n%lf\n", x, y);
}

void door::readdata(FILE* fp) {
    fscanf_s(fp, "%lf%lf", &x, &y);
}

void SKILL_1::storedata(FILE* fp) {
    fprintf(fp, "%d\n%lf\n%lf\n%d\n%d\n%f\n%f\n%lf\n%lf\n%f\n%f\n", islock, n, duration, count, wait, button_x, button_y, CD, countTime, x, y);
}

void SKILL_1::readdata(FILE* fp) {
    fscanf_s(fp, "%d%lf%lf%d%d%f%f%lf%lf%f%f", &islock, &n, &duration, &count, &wait, &button_x, &button_y, &CD, &countTime, &x, &y);
}
///////////////////////////以上为各个类里的存读档函数

void all::gameover()
{
    HistoricalGamelevel = max(Gamelevel, HistoricalGamelevel);
    storedata();
    while (1)
    {
        BeginBatchDraw();
        cleardevice();
        mouse.getmouse(graph);
        putimage(-graph.x, -graph.y, &im_gameover);

        TCHAR str[20]; // 定义字符数组
        setbkmode(TRANSPARENT); // 透明显示文字
        settextcolor(YELLOW);  // 设置字体颜色

        swprintf_s(str, _T("%d"), Gamelevel); //转换为字符串
        settextstyle(30, 0, _T("华文琥珀"));
        outtextxy(700, 250, str); // 输出文字



        if (-graph.x + 380 <= mouse.x && mouse.x <= -graph.x + 380 + 447 && -graph.y + 400 <= mouse.y && mouse.y <= -graph.y + 400 + 96)
        {
            putimagepng(-graph.x + 380 - 25, -graph.y + 400 - 10, &im_return_menu2);
            if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
                all::menu();
            }
        }
        else
            putimagepng(-graph.x + 380, -graph.y + 400, &im_return_menu);

        FlushBatchDraw();
    }
}

////////////////////加载页面
void all::loading() {

    int m = 0;
    int i;
    float r = 50;
    float x[5];
    int d[5] = { 0 };
    for (i = 0; i < 5; i++) {
        x[i] = WIDTH / 5 * 2 + i * WIDTH / 5 / 3;
    }

    /// ////////////随机加载图片
    IMAGE pic1;
    if (rand() % 4 == 0) {
        loadimage(&pic1, _T("loading04.jpg"), WIDTH, HEIGHT, TRUE);
    }
    else if (rand() % 4 == 1) {
        loadimage(&pic1, _T("loading03.jpg"), WIDTH, HEIGHT, TRUE);
    }
    else if (rand() % 4 == 2) {
        loadimage(&pic1, _T("loading06.jpg"), WIDTH, HEIGHT, TRUE);
    }
    else if (rand() % 4 == 3) {
        loadimage(&pic1, _T("loading05.jpg"), WIDTH, HEIGHT, TRUE);
    }

    for (m = 0; m < 150; m++) {
        BeginBatchDraw();
        cleardevice();

        putimage(-graph.x, -graph.y, &pic1);

        setfillcolor(HSVtoRGB(0, 0, 1));
        for (i = 0; i < 3; i++) {
            fillcircle(x[i] - graph.x, HEIGHT / 2 - graph.y, 30 - 0.2 * fabs(WIDTH / 2 - x[i]));
            if (d[i] == 0) {
                x[i] += 5;
            }
            else {
                x[i] -= 5;
            }
            if (x[i] > WIDTH / 5 * 3 && d[i] == 0) {
                d[i] = 1;
            }
            if (x[i] < WIDTH / 5 * 2 && d[i] == 1) {
                d[i] = 0;
            }
        }
        setfillcolor(HSVtoRGB(0, 0, 1));
        solidroundrect(50 - graph.x, 550 - graph.y, 1150 - graph.x, 580 - graph.y, 10, 10);
        setfillcolor(HSVtoRGB(0, 0, 0.5));
        solidroundrect(60 - graph.x, 552 - graph.y, 70 + m * 1080 / 150 - graph.x, 578 - graph.y, 10, 10);

        FlushBatchDraw();
        Sleep(15);
    }
}







